Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper?
    primarykey
    data
    text
    <p>I'm working with Doctrine2 for the first time, but I think this question is generic enough to not be dependent on a specific ORM. </p> <p><strong>Should the entities in a Data Mapper pattern be aware - and <em>use</em> - the Mapper</strong>?</p> <p>I have a few specific examples, but they all seem to boil down to the same general question. </p> <p>If I'm dealing with data from an external source - for example a <code>User</code> has many <code>Messages</code> - and the external source simply provides the latest few entities (like an RSS feed), how can <code>$user-&gt;addMessage($message)</code> check for duplicates unless it either is aware of the Mapper, or it 'searches' through the collection (seems like an inefficient thing to do).</p> <p>Of course a Controller or Transaction Script could check for duplicates before adding the message to the user - but that doesn't seem quite right, and would lead to code duplication.</p> <p>If I have a large collection - again a <code>User</code> with many <code>Messages</code> - how can the <code>User</code> entity provide limiting and pagination for the collection without actually proxying a Mapper call?</p> <p>Again, the Controller or Transaction Script or whatever is using the Entity could use the Mapper directly to retrieve a collection of the <code>User</code>'s <code>Messages</code> limited by count, date range, or other factors - but that too would lead to code duplication. </p> <p><strong>Is the answer using Repositories and making the Entity aware of them</strong>? (At least for Doctrine2, and whatever analogous concept is used by other ORMs.) At that point the Entity is still relatively decoupled from the Mapper.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload