Search code examples
cakephprelationships

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.


Solution

  • 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