Skip to main content
7 events
when toggle format what by license comment
Feb 26, 2014 at 18:37 vote accept CommunityBot
Feb 23, 2014 at 20:37 comment added Fge I'd be Repository::save($person). The mapper is not responsible for this. It is only responsible for for mapping Database <-> Model. The mapper can be part of of the repository (either fully integrated, slightly violating single responsibility, or as an extra class passed to the repository at construction time). As a rule of thumb: the model interacts with the repository only, the mapper is called by the repository only, the repository calls the database as only class.
Feb 23, 2014 at 20:26 comment added user37349 Thanks. So with using mappers, would I still do $person->save() - where Person just calls the save method of PersonMapper or would I have do PersonMapper::save($person)? I did a quick search for 'PHP Mapper' and 'PHP ORM' but all I seem to get is links for software that uses this approach.
Feb 23, 2014 at 20:04 comment added Fge Yes, it is a solid approach. Split these fields on a database only level though. Splitting them on the model level would introduce a new City entity :). About the naming: its something personal really. MySql documentation uses plural too. Imho it really doesn't matter what you do, just stick to it - that's the real important thing.
Feb 23, 2014 at 19:45 comment added user37349 I was taught that a table name should reflect what a single record represents. So it's Person because it represents one person, where as PersonDates would reflect multiple dates – dob & dod – so it should be plural. It's worked for me so I've stuck with it. I do use foreign keys, but I've had problems deleting tables via phpMyAdmin once foreign keys are defined, so I tend to wait until I'm certain on my structure.
Feb 23, 2014 at 19:44 comment added user37349 So are you basically saying (without going into the complex approach) to keep the structre as it is - aside from splitting out city, postcode and county from address - and separate the class into object and mapper?
Feb 23, 2014 at 18:27 history answered Fge CC BY-SA 3.0