你有几个选择。您可以设置一个模型recursive
属性:
$this->Post->recursive = -1;
$posts = $this->Post->find('all');
Alterantively,您可以指定recursive
作为一个选项来搜索:
$posts = $this->Post->find('all', array(
'recursive' => -1,
'conditions' => ...
);
您也可以在安置自己的模型中使用Containable
行为。在这种情况下,你可以指定一个空集:
class Post extends AppModel {
var $actsAs = array('Containable');
}
$this->Post->contain();
$posts = $this->Post->find('all');
或者,在查询中指定:
$posts = $this->Post->find('all', array(
'contain' => false,
);
为Containable
行为的好处是,当你以后关联其他型号你的文章。假设你实现了一个Tag模型。现在,你想找到它的标签后,而不是使用模式:
$posts = $this->Post->find('all', array(
'contain' => array('Tag'),
);
感谢您的意见。我尝试了'contains'=> false方法,但由于某种原因它仍然返回关联的模型。查看我的代码编辑 – AlexBrand 2011-04-07 20:44:52
您是否在您的模型中包含“Containable”行为?看到我上面的编辑。 – 2011-04-07 21:15:45
我错过了...非常感谢! – AlexBrand 2011-04-07 21:46:21