Hello everyone,
is it possible to add a condition defined in a scope of a related model to the parent models where clause? Conditions in joined models are moved to the ON clause which is fine most of the time - but this doesn’t work for my case, where the related model’s condition depends on yet another model.
Simplified example:
/**
* This is the model class for table "Group".
*/
public function scopes()
{
return array(
'valid'=>array(
'with'=>array('member:webuser'),
'condition'=>"`{$this->tableAlias}`.`status`=".self::STATUS_PUBLIC." OR (`{$this->tableAlias}`.`status`=".self::STATUS_PRIVATE." AND `member`.`status`=".Member::STATUS_MEMBER.")",
),
);
}
Works on it’s own, doesn’t work like this, as the ON condition needs table Member to be already joined:
Post::model()->with('group:valid')->findAll();
I could write a scope in "Post" but there are a lot of tables that need this very scope. Ideas?
Thank you!