I have SubjectGroup, which hasMany Subject.
class SubjectGroup extends AppModel {
public $hasMany = array(
'Subject' => array('order' => 'Subject.name')
);
}
class Subject extends AppModel {
public $belongsTo = array('SubjectGroup');
}
I want to get all SubjectGroups, and recursively retrieve their Subjects, but only the Subjects that have a status of 2.
$this->SubjectGroup->find('all', array(
'contain' => 'Subject.status != 2',
'order' => 'SubjectGroup.name'
));
There are no errors, but it just returns all Subjects, even the ones with status = 2.
Well, I finally discovered two problems. I was trying to add an
$actsAsdefinition to the controller, to bring in the behaviour. I completely forgot it’s not the model. You have to bring in the behaviour in the controller action.But anyway, the condition only seems to work if I use the very basic syntax of:
'contain' => 'Subject.status != 2'Anything more complex doesn’t seem to work for me: