문제

Model1 HABTM Model2. In Model1's model class, I have the following code:

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

The result has every related Model2 record. It should only return the Model2 record if that record's name is "foo". No error, the condition is just never added to the SQL.

Containable is declared in AppModel's actsAs property.

What gives?

도움이 되었습니까?

해결책

My syntax was wrong. These syntaxes are correct:

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

or

        $this->contain('Model2', array(
            'Model2' => array(
                'conditions' => array('Model2.name' => 'foo')
            )
        ));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top