Simon
Simon

Reputation: 1733

Codeigniter Datamapper many-to-many relationships

I’m setting up relationships in my models using DataMapper but I’ve hit a wall.

I have a RealEstate class, a Client class and a Position class which all have many to many relationships.

  1. Client can have the Position ‘buyer’ in a RealEstate
  2. Same Client can have the Position ‘seller’ in another RealEstate

So for a given RealEstate it’s easy to find all the Clientss attached to it, but how can I also include what Position those clients have for the specific RealEstate?

Upvotes: 0

Views: 477

Answers (1)

J0HN
J0HN

Reputation: 26941

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. It effectively emulates many-to-many relationship between RealEstate and Client that have an additional info (Position) in it.

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.

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.

Upvotes: 1

Related Questions