Add related scope condition to WHERE clause

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(



			'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:


I could write a scope in "Post" but there are a lot of tables that need this very scope. Ideas?

Thank you!



Im looking for this solution as well.

Something like this?

array( 'vacancy_id', 'exist', 'className' => 'Vacancy', 'attributeName' => 'id', 'criteria' => array( 'scopes' => 'active' ) ),

class Vacancy extends CActiveRecord{

  public function scopes(){

    return array(

      'active' => array( 'condition' => 'is_deleted=0' )