How about: *Seller Model: * *belongsTo agency* * * *Agency Model: **hasMany seller* * * Because Agency doesn't really belong to the seller... an agency has many sellers (if I understand you correctly) and a seller belongs to an agency
2009/6/30 Bryan Paddock <[email protected]> > > Hey JD, > > Ah... I'm confused as to why I would need a HABTM and a join table for > a fairly simple relationship. > > example of the structure: > > Seller.id > Seller.name > Seller.agency_id > etc > > and > > Agency.id > Agency.name > etc > > Each seller can only belong to one agency. > Each agency can have any number of sellers. > > I've defined $hasOne and $belongsTo but cake complains that there is > no agency.seller_id field which is correct because that would imply > that each agency can only have one seller. > > Hmmmmm..... > > On Mon, Jun 29, 2009 at 8:25 PM, JD Daniels<[email protected]> wrote: > > You need to look at hasAndBelongsToMany > > > > http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM > > > > Bryan Paddock wrote: > > > > Argh.. I hate gmail shortcut keys. > > > > Anyways continuing mail: > > > > Heya all, > > > > Theres something I'm not doing right here... > > > > I have a User model which has one Seller model linked to it which in > > turn can have an Agency model linked to it. > > > > User Model: > > hasOne seller. > > > > Seller Model: > > belongsTo user > > > > Agency Model: > > belongsTo seller > > > > Now when I call $this->User->find('all') it complains that there is no > > foreign key in the agency table. That would be impossible because then > > that would mean only one agency can belong to one seller. > > > > How do I set it up so that any number of agencies can belong to any > > number of sellers? I'm missing something really stupid here.... > > > > Thanks! > > > > Bryan > > > > > > > > > > > > > > On Mon, Jun 29, 2009 at 7:06 PM, Bryan Paddock<[email protected]> > > wrote: > > > > > > Heya all, > > > > Theres something I'm not doing right here... > > > > I have a User model which has one Seller model linked to it which in > > turn can have an Agency model linked to it. > > > > User Model: > > hasOne seller. > > Seller Model: belongsTo user > > Agency Model: belongsTo seller > > > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
