Hello everyone, I can’t understand how HAS_MANY relation works. I have model Place with relation:
'movies' => array(self::HAS_MANY, 'Movies', 'id_place')
And I can’t figure out how to filter Movies model, it always selects all related Movies, I tried to describe condition with:
$this->loadModel($id)->with(array('movies' => 'column=value'))
but it selects all movies, it always selects all movies doesn’t matter if I use “with” statement or not, tried to add together=>false to relation, doesn’t matter. What am I doing wrong?
P. S. Sorry for my bad English
Here is a description: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#with-detail
You can pass an array as a parameter to the with() method.
In this case the key of the array should be the related model and the value of the array should be another array. This second array should be a criteria compatible with CDbCriteria.
In your case I am gessing something like this would work:
'on'=>'column = :value',
You could also put the condition in a condition statement for the relation like this:
'condition'=>'column = :value',
I believe that is you put your condition into the condition statement of the relation the join will act like an inner join. If you want to keep the left join behavior that is the default of relations then put your condition into the ‘on’ statement.