Why there are additinonal condition when I perform relation? Help

Anyone can explain this.

I have a model file called TranslationOriginal

and here is the relations

    public function relations(){

        return array(

            'translation_user' => array(self::HAS_MANY, 'TranslationUsers', 'translation_original_id', 'order' => '`translation_user`.confirmed DESC')



    public function search(){

        $criteria = new CDbCriteria();


        $conditions = array();

        $joinType   = 'INNER JOIN';

        $conditions[] = '`translation_user`.translation_language_id = \''. mysql_escape_string($this->translation_language_id) .'\'';



            $joinType = 'LEFT JOIN';

            $conditions = array();

            $criteria->addCondition('t.id NOT IN (SELECT DISTINCT translation_original_id FROM translation_users)');



            $criteria->compare('t.text', $this->text, true);


        $criteria->with = array(

            'translation_user' => array(

                'condition' => join(" AND ",$conditions),

                'joinType'  => $joinType




        return new CActiveDataProvider(get_class($this), array(

                'criteria' => $criteria



as you see, I use search model that return CActiveDataProvider, I throw this into view that used CListView widget.

what I ask is, when I try to see on Logger, I’m wondering why I get a different query,

there are additional condition, and I don’t know where is come from, the original query should like this :

Querying SQL: SELECT `t`.`id` AS `t0_c0`, `translation_user`.`id` AS

`t1_c0`, `translation_user`.`translation_language_id` AS `t1_c1`,

`translation_user`.`translation_original_id` AS `t1_c2`,

`translation_user`.`text` AS `t1_c3`, `translation_user`.`confirmed` AS

`t1_c4` FROM `translation_original` `t` RIGHT JOIN `translation_users`

`translation_user` ON

(`translation_user`.`translation_original_id`=`t`.`id`)  WHERE 

(`translation_user`.translation_language_id = '3') ORDER BY

`translation_user`.confirmed DESC

but, what I get when I see profiler is like this (I make bold the addition):

Querying SQL: SELECT t.id AS t0_c0, translation_user.id AS

t1_c0, translation_user.translation_language_id AS t1_c1,

translation_user.translation_original_id AS t1_c2,

translation_user.text AS t1_c3, translation_user.confirmed AS

t1_c4 FROM translation_original t RIGHT JOIN translation_users

translation_user ON

(translation_user.translation_original_id=t.id) WHERE [b](t.id IN

(11, 12, 13, 14, 15, 16, 17, 18, 19, 20))[/b] AND

(translation_user.translation_language_id = ‘3’) ORDER BY

translation_user.confirmed DESC

this is the additional condition that I see on profiler, where as I don’t define it in my script, neither in model nor controller.

... WHERE (`t`.`id` IN

(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)) AND ...

I need to remove this additional condition.

anyone could explain me why is this?

Thankyou in advance,

is it "IN" or "NOT IN" as you have this code

$criteria->addCondition('t.id NOT IN (SELECT DISTINCT translation_original_id FROM translation_users)');

Hi thanks for the reply,

yeah, I have NOT IN inside the code, but I wondering why I get "IN" on the conditional when query executed. so I thought it was additional by Yii when I perform relationship.