[英]Codeigniter Datamapper many-to-many relationships
I'm setting up relationships in my models using DataMapper but I've hit a wall. 我正在使用DataMapper在模型中建立关系,但遇到了麻烦。
I have a RealEstate
class, a Client
class and a Position
class which all have many to many relationships. 我有一个RealEstate
类,一个Client
类和一个Position
类,它们都有许多对许多的关系。
Client
can have the Position
'buyer' in a RealEstate
Client
可以在RealEstate
拥有“买方” Position
Client
can have the Position
'seller' in another RealEstate
同一Client
可以在另一个RealEstate
拥有Position
“卖方” So for a given RealEstate
it's easy to find all the Clients
s attached to it, but how can I also include what Position
those clients have for the specific RealEstate
? 因此,对于给定的RealEstate
可以很容易地找到与其相连的所有Clients
,但是我又如何包括这些客户在特定RealEstate
所处的Position
呢?
I think you have an incorrect design for it. 我认为您的设计不正确。 It really should be many-to-many relationship between Client
and Position
, but only one-to-many relationship between Position
and RealEstate
, with one on RealEstate
side. Client
和Position
之间确实应该是多对多关系,但Position
和RealEstate
之间应该只有一对多关系,其中一个在RealEstate
端。 It effectively emulates many-to-many relationship between RealEstate
and Client
that have an additional info ( Position
) in it. 它有效地模拟了RealEstate
和Client
之间的多对多关系,其中包含附加信息( Position
)。
Speaking in terms of problem domain, any role ( Position
) is attached to specific RealEstate
, but any Client
can have arbitrary number of roles and any RealEstate
can(?) have multiple roles attached to it. 就问题域而言,任何角色( Position
)都附加到特定的RealEstate
,但是任何Client
可以具有任意数量的角色,任何RealEstate
可以(?)都具有多个角色。
I don't have CodeIgniter 2 at fingertips, so can't provide code samples, but let me know if you really need it - I have it CodeIgniter 2 at home. 我没有指尖的CodeIgniter 2,因此无法提供代码示例,但是请告诉我您是否真的需要-我在家中有CodeIgniter 2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.