0

模型 1 HABTM 模型 2。在 Model1 的模型类中,我有以下代码:

public class Model1 extends AppModel
{
    function getResult()
    {
        $this->contain('Model2', array(
            'conditions' => array('Model2.name' => 'foo')
        ));
        $result = $this->findByRelatedId($careNoteId);
        return $result;
    }
}

结果有每个相关的 Model2 记录。如果该记录的名称是“foo”,它应该只返回 Model2 记录。没有错误,条件只是从未添加到 SQL 中。

Containable 在 AppModel 的actsAs属性中声明。

是什么赋予了?

4

1 回答 1

0

我的语法错误。这些语法是正确的:

        $this->contain(array(
            'Model2' => array(
                'conditions' => array('Model2.name' => 'foo')
            )
        ));

或者

        $this->contain('Model2', array(
            'Model2' => array(
                'conditions' => array('Model2.name' => 'foo')
            )
        ));
于 2013-12-07T01:47:37.720 回答