Monday, April 10, 2017

Does the datamapper convert the SGBD result as an object?

Leave a Comment

I am working with MySql and results/rows are returned within an array.

I do understand that in the end, the model layer "goal" is to return an object once the SGBD query is processed.

So, should the process of converting rows (or a single row) into an object be integrated in the DataMapper (which is part of the Model layer) or should it be the responsibility of a third service that would be injected in the DataMapper?

Thank you

2 Answers

Answers 1

So, should the process of converting rows (or a single row) into an object be integrated in the DataMapper.

Well yes it's the responsibility of the data mapper. It should return an entity, not a result set.

or should it be the responsibility of a third service that would be injected in the DataMapper?

This is also a possibility, google to "UnitOfWork" I think that's were you are looking for. https://www.sitepoint.com/implementing-a-unit-of-work/

You can also take a look at the doctrine source https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityManager.php

Answers 2

Yes, I agree with Sander, your Business logic must be at another layer. But It should not be in controller.

enter image description here

Classic MVC compresed of 3th parts:

A model stores data that is retrieved according to commands from the controller and displayed in the view.
A view generates new output to the user based on changes in the model.
A controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., scrolling through a document).

Any parts in MVC - is independent pattern.

Exist active and passive MVC. Classic MVC is active.

In Active Model within three components, the Model is in action. The main difference with Passive Model implementation is, in Active Model implementation the Model notifies the View when the Model is changed by Controller. The pictorial representation will clear it more.

In the active business model, the logic is in the model, and controller is thin.

you can to divide DataMapper and add new service for transformation your data, return data to model, and returns data to controller

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment