flaab Posted June 25, 2007 Share Posted June 25, 2007 Hi =) I'm trying out CakePhp and i've readed all the manual. The hasMany relationships are pretty cool and they are easy to use. But...even though I've seen plenty of examples I haven't figured out the way to implement multiple hasMany relationships. Here's a simple hasMany relationship. class user extends AppModel { var $name = "User"; var $validate = array(); /** * RELACIONES * 1) hasMany Challenges * 2) hasMany Files * 3) hasMany Rounds (Como ganador) */ var $hasMany = array('Challenge') => array('className') => 'Challenge', 'conditions' => 'Challenge.active = 1', 'order' => 'Challenge.created DESC', 'limit' => '', 'foreignKey' => 'user_id', 'dependent' => 'true', 'exclusive' => 'false', 'finderSql' => '' ) ); } But...What if my User has more hasMany relationships with other tables? Like...besides putting challenges on the web, it has many articles written? How can I define both? Thanks. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted June 25, 2007 Share Posted June 25, 2007 I'm almost new to CakePHP but I have a project which includes a dealer-model containing the following line: var $hasMany = array('Product','Advert'); It does what I thought it would... let me access multiple Products and multiple Adverts associated with a single user: $this->set('myProducts', $this->Dealer->Product->findAll('user_id = 4',array('id','header','user_id'),null,5)); $this->set('myAdverts', $this->Dealer->Advert->findAll('user_id = 4',array('id','header','user_id'),null,5)); Maybe it can help you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.