3 ms·
separation of the entities and repositories is useful in many ways. For example, you can stub the repository and avoid persisting objects in tests, and only te
by riffraff 10y ago
separation of the entities and repositories is useful in many ways.
For example, you can stub the repository and avoid persisting objects in tests, and only test persistence in the appropriate ones.
Or, you always know that operations you call on an entity won't touch the database, so you avoid a whole class of problems (think: accidental N+1 queries in a loop).
Or, by making the query interface private to the repository, you avoid accidental leakage of storage details (think: `default_scope` impacting associations)
I believe Ecto/Phoenix adopts a similar pattern http://www.phoenixframework.org/docs/models http://www.phoenixframework.org/docs/models