PHP Mapper pattern for link tables
I'm finally getting my head around using the Mapper design pattern to structure an object oriented system I'm building in PHP.
I have classes like User
, and Project
, each with corresponding MySQL tables (and Mapper classes eg ProjectMapper
, UserMapper
)
What I want to know, is how to approach link tables while using this pattern. I have another class Invitation
which invites a User
to work on a Project
. (It's just a standard link table, with a project_id
and a user_id
).
Say I want to get a Collection of all the users assigned to a particular project, firstly, where should this function go? ProjectMapper
class, InvitationMapper
class?
And secondly. how can I make this neat and sensible?
Thanks in advance.
Just take a look at this very interesting article - it helped me a lot when I was working on my own model, which should be efficient and easy to use:
http://www.survivethedeepend.com/zendframeworkbook/en/1.0/implementing.the.domain.model.entries.and.authors
The author explains how to build a reliable model in Zend Framework, but you can use his ideas also in other frameworks or just building your own model without any framework.
I recommend you also (if you are working with Zend) to skip the testing parts - the topic itself is very complex and the testing can be done, when you are done with your model.
Building my own model, I modified a few things, so if you will have further questions - you know - don't hesitate to ask them ;)
链接地址: http://www.djcxy.com/p/9614.html上一篇: 使用外部数据源实现域模型和数据映射器模式
下一篇: 链接表的PHP映射器模式