Timeline for Keeping an MVC model loosely coupled from the DB?
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 24, 2011 at 8:02 | comment | added | Industrial | Hi David! Just wanted to thank you again for this answer. Definitely one of the best I've received on StackExchange! | |
| Aug 10, 2011 at 7:50 | vote | accept | Industrial | ||
| Aug 9, 2011 at 10:14 | history | migrated | from stackoverflow.com (revisions) | ||
| Aug 8, 2011 at 19:26 | comment | added | David | @Industrial: Keep in mind also that the repository methods don't have to just be CRUD. Lots of intelligence can be baked into that code. A lot of the more complex ones can have a lot of internal code which transforms data from the database. Or, if the complex ones involve many trips to the database, then for performance gains you can put the logic in a stored procedure and the DAL method just passes through to that procedure and translates the results into models. | |
| Aug 8, 2011 at 19:25 | comment | added | David | @Industrial: For example, if you use an ORM, then that ORM would be referenced by your DAL (which is isolated from the domain models) and would transform your models into data access accordingly. Or if you do direct database access with manual SQL, you'd do that in your DAL's repository methods and translate the results of the SQL queries into domain models before returning them. | |
| Aug 8, 2011 at 19:23 | comment | added | David | @Industrial: There are a number of ways to connect models to persistence, but so far the only method I've found which truly satisfies my desire to separate concerns is to have repository interfaces in the domain which are externally implemented by a DAL. The repository methods accept and return domain models, and internally converts between those and any generated database entities. (To be honest, I haven't done this much in PHP.) So you can use a DAL framework to auto-generate all your DB CRUD, etc. and then write your repositories as an interface between that stuff and your models. | |
| Aug 8, 2011 at 18:33 | comment | added | Industrial | Hi David. Thanks for your extensive reply! Whilst maintaining a high level of loose couplings, how would you connect the models with a database connector? | |
| Aug 8, 2011 at 18:07 | history | answered | David | CC BY-SA 3.0 |