Page 1 of 1
Data mapper with MVC
Posted: Mon Oct 16, 2006 10:53 am
by Luke
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!
Posted: Mon Oct 16, 2006 11:59 am
by johno
Look at Torpedeo in my signature

Posted: Mon Oct 16, 2006 12:17 pm
by Luke
Can you only download source if you have subversion on google code??
Posted: Mon Oct 16, 2006 12:23 pm
by johno
The Ninja Space Goat wrote:Can you only download source if you have subversion on google code??
I don't clearly understand what you mean. Do you want to download source code? You have to use svn checkout or svn export.
Posted: Mon Oct 16, 2006 12:38 pm
by Luke
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... ??
Posted: Mon Oct 16, 2006 12:59 pm
by johno
The 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... ??
SVN/CVS version control is essential stuff so developers should be using it anyway

Ok seriously, the reason is that Torpedeo is in early development stage so I don't really cared about that. Sourceforge is of course better, but more complicated. I wanted it to be simple.
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.
Posted: Mon Oct 16, 2006 2:08 pm
by Christopher
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.