PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] CakePHP 2.x hasMany that belongsTo another table

 January 28, 2022     cakephp, relationships     No comments   

Issue

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



Answered By - Jacek B Budzynski
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing