Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the datamapper convert the SGBD result as an object?

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

like image 837
Vincent Avatar asked Mar 31 '17 13:03

Vincent


1 Answers

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 what 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

like image 51
Sander Visser Avatar answered Oct 17 '22 19:10

Sander Visser