problem with createInCondition

Hi all,

I’ m doing this (query with an IN condition):




$ids=array(1,2,3);

$inCondition=User::model()->dbConnection->commandBuilder->createInCondition(User::model()->tableSchema, 'id', $ids);

$result=User::model()->findAll('not '.$inCondition);



…and I’m getting that :




CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.id' in 'where clause'



The log shows this query :


SELECT * FROM `user` `t` WHERE not `user`.`id` IN (1, 2, 3)

…where (I think) it should be :

[font="arial, verdana, tahoma, sans-serif"] [/font]

[font="arial, verdana, tahoma, sans-serif"][size="2"]


SELECT * FROM `user` `t` WHERE not `t`.`id` IN (1, 2, 3)

[/size][/font]

[font="arial, verdana, tahoma, sans-serif"] [/font]

[font="arial, verdana, tahoma, sans-serif"][size="2"]How come the table name in the where clause is not replaced by the table alias ? Am I missing something ?[/size][/font]

[font="arial, verdana, tahoma, sans-serif"][size="2"]Thanks for your help[/size][/font]

[font="arial, verdana, tahoma, sans-serif"][size="2"][/size][/font]

Try:




$criteria = new CDbCriteria();

$criteria->addInCondition('id', array(1,2,3));

$result=User::model()->findAll($criteria);



samdark code is more cleaner and easy to read… but if you want to stick with your code… you can send the 4th parameter to createInCriteria(), check the documentation - http://www.yiiframework.com/doc/api/CDbCommandBuilder#createInCondition-detail

thanks to both of you, it works fine now…

(I think it used to work for 1.0.6 has this code is from an old app)

8)