CakePHP 2.x hasMany that belongsTo another table
CakePHP 2.x hasMany that belongsTo another table
我有我的基础模型 Affiliate 有许多 AffiliatePayout 和这些 AffiliatePayouts 属于 支出。现在我正在做一个 $this->Affiliate->find('all', array())
并返回一个 AffiliatePayouts 数组,但我还想获得属于的 Payout AffiliatePayout 随结果一起返回。一天中的大部分时间我都在绞尽脑汁想弄明白这个问题,但似乎找不到答案。
试试这个:
$this -> Affiliate -> find('all', array('contain' => 'Payout'))
这里有更多关于可包容行为的信息
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
感谢@Jacek B Budzynski 的帮助,我做到了 $this->Affiliate->find('all', array('contain' => array('AffiliatePayout' => array('Payout')));
我能够让它工作。我的用例比发布的用例更高级,但这解决了我的问题。谢谢@Jacek
我有我的基础模型 Affiliate 有许多 AffiliatePayout 和这些 AffiliatePayouts 属于 支出。现在我正在做一个 $this->Affiliate->find('all', array())
并返回一个 AffiliatePayouts 数组,但我还想获得属于的 Payout AffiliatePayout 随结果一起返回。一天中的大部分时间我都在绞尽脑汁想弄明白这个问题,但似乎找不到答案。
试试这个:
$this -> Affiliate -> find('all', array('contain' => 'Payout'))
这里有更多关于可包容行为的信息
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
感谢@Jacek B Budzynski 的帮助,我做到了 $this->Affiliate->find('all', array('contain' => array('AffiliatePayout' => array('Payout')));
我能够让它工作。我的用例比发布的用例更高级,但这解决了我的问题。谢谢@Jacek