I have come to the decision to use Data Mapper instead of Active Record. My question is regarding using Data mappers within a Model-View-Controller architecture. Those of you who have built a system like this... how was it structured? Here's what came to mind for me:
I would have two main abstract classes: Mysql_DataMapper, Mysql_DataModel. For each model, I would override both of these classes... each Mysql_DataModel object would use it's corresponding Mysql_DataMapper object to know how to store itself in the database... does this sound about right? Does anybody have any code example for a data-mapper type solution? Thanks a lot guys!
Data mapper with MVC
Moderator: General Moderators
- johno
- Forum Commoner
- Posts: 36
- Joined: Fri May 05, 2006 6:54 am
- Location: Bratislava/Slovakia
- Contact:
SVN/CVS version control is essential stuff so developers should be using it anywayThe Ninja Space Goat wrote:That's what I mean... seems stupid to force users to use SVN just to download source... sourceforge lets you download zipped packages and stuff... ??
Anyways this is offtopic. If you want to know how it works. Look at ClassMapping which is composed of FieldMappings.
http://torpedeo.googlecode.com/svn/trun ... apping.php
http://torpedeo.googlecode.com/svn/trun ... apping.php
ClassMappings knows how to map rows from sql select to class. It maps row to transfer object (mapRowToTransfer() method).
That's for a good start.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
To respond to the original post, I don't think the Mapper should be extended to create the model. I believe a Mapper is more like a Connection class in that it does not contain business logic -- unlike Active Record which can. I think these days they add a lightweight O/R Mapper to the Active Record (ala Rails) when they want business logic included.
(#10850)