[Yii 1.1] Set "base" condition through relation's criteria


(David Hirtz) #1

Hello everyone,

maybe I’m missing something, but while I understand that conditions declared in a relation’s CDbCriteria are put in the ON clause of the JOIN statement I sometimes wish there was a way to manipulate the query’s WHERE condition through relations joined via “with”.

Basic example:




$users=User::model()->with('friendship:friendly')->findAll();



Friendship:




public function friendly()

{

	$this->dbCriteria->addBaseCondition("`{$this->tableAlias}`.`status` IS NULL OR `{$this->tableAlias}`.`status`>:hated");

	$this->dbCriteria->params[':hated']=self::STATUS_HATED;

}



The method “addBaseCondition” would apply the condition not to the ON clause but to the WHERE condition of the query. Has anyone an idea if this would be possible with a bit of tweaking? Going through the framework’s code it’s probably a big thing, but it would be pretty handy…

Thanks,

David