Chris Hallgren
Chris Hallgren

Reputation: 58

CakePHP 2.x hasMany that belongsTo another table

I have my base Model Affiliate that hasMany AffiliatePayout and these AffiliatePayouts belongTo a Payout. Now I'm doing a $this->Affiliate->find('all', array()) and its returning an array of AffiliatePayouts but I would also like to get the Payout that belongsTo the AffiliatePayout returned along with the results. I've racked my brain most of the day trying to figure this out and can't seem to find an answer.

Upvotes: 0

Views: 321

Answers (2)

Chris Hallgren
Chris Hallgren

Reputation: 58

Thanks to the help of @Jacek B Budzynski I did $this->Affiliate->find('all', array('contain' => array('AffiliatePayout' => array('Payout'))); I was able to get it to work. My use case is a bit more advanced that what is posted but this fixed my issue. Thank you @Jacek

Upvotes: 0

Jacek B Budzynski
Jacek B Budzynski

Reputation: 1413

Try this:

$this -> Affiliate -> find('all', array('contain' => 'Payout'))

Here you have more info about Containable Behavior

http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

Upvotes: 1

Related Questions