Yii Framework Forum: [Yii 1.1] Set "base" condition through relation's criteria - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[Yii 1.1] Set "base" condition through relation's criteria Rate Topic: -----

#1 User is offline   dmx 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 08-November 10

Posted 09 October 2014 - 02:53 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users