中的条件包含cakephp find

中的条件包含cakephp find,php,cakephp,cakephp-1.3,php-5.3,Php,Cakephp,Cakephp 1.3,Php 5.3,在CakePHP中,在find查询的contain中设置以下条件是好的还是坏的做法: $data = $this->SomeModel->find('all', array( 'contain' => array( 'AnotherModel' => array( 'conditions' => array( // some conditions )

在CakePHP中,在find查询的
contain
中设置以下条件是好的还是坏的做法:

$data = $this->SomeModel->find('all', array(
    'contain' => array(
        'AnotherModel' => array(
            'conditions' => array(
                // some conditions
            )
        )
    )
));
在哪些情况下,将条件放在包含中是有用的,以及何时应该使用它或不使用它。对不起,我还是不明白


谢谢

我不确定这是否是个好主意。。。首先,我将假设此特定案例要求您指定此案例特有的条件,即,不足以将
SomeModel
模型关系标准应用于
AnotherModel

我的建议是,您应该将这些条件放在总体查找条件中,因为contain指定返回哪些链接模型(控制引擎盖下的联接)。与SQL一样,您可以联接另一个表,并在
WHERE
子句中指定要匹配的记录

,您可以在包含中指定条件,但这些条件不会影响不像整体条件一样加入模型的结果

我会这样做:

$data = $this->SomeModel->find('all', array(
    'contain' => array('AnotherModel'),
    'conditions' => array(
        // some conditions relating to AnotherModel
    )
));

如果为联接表设置条件,则此方法返回错误。例如:“条件”=>array('AnotherModel.active'=>1)