Gar*_*ett 3 cakephp model containable cakephp-1.2
当我尝试:
// Removed the limit to ensure that all of the group notes items can be found and collapsed
$recent_notes = $this->User->Note->find('all', array(
'recursive' => 2,
'order' => 'Note.created DESC',
'conditions' => $conditions,
'contains' => array(
'NotesUser', 'Poster', 'Comment' => array('Poster')
)
));
Run Code Online (Sandbox Code Playgroud)
它不会限制输出 - 我得到每个相关的模型.但是,当我没有指定recursive为2,或者如果我指定为1,我错过了Comment=>Poster模型.
我怎样才能获得我需要的模型?谢谢!
要仅获取所需的模型,请使用[可包含行为]:
'contain'单数,而不是'contains'复数$actsAs在模型中设置变量:public $actsAs = array('Containable');我认识的每个人都$this->recursive = -1;在AppModel中设置...这默认所有内容都是递归-1所以你不必再次设置它,除非你想要包含更多的数据......在这种情况下,我几乎总是使用contain(),而不是$recursive.