Active Records IN statement


We are running Yii 1.03. This is the first time I have been experimenting with Active Records - up to now we have just been using custom SQL queries. I feel I am misunderstanding something though…

Take this code:

$sqlCondition = "person_id IN (:personId)";

$sqlParams['personId'] = '1111,2222';

$TransferObject = MTransfer::model()->findAll(array(

					'condition' => $sqlCondition,

					'params' => $sqlParams


I would have thought this would return two objects, one for person_id 1111, and one for person_id 2222. However it only returns one object - in this case 1111.

If I reverse the numbers (‘2222,1111’) then it will give me the object for person 2222 instead.

Forgive me if I am misunderstanding something obvious. How can I get this query to work?

How do you check the amount of records returned? Did you loop through the results -foreach? Did you count the returned value?

Parameter name in the params should be the same as in condition (including ‘:’):

$sqlCondition = "person_id IN (:personId)";

$sqlParams[’:personId’] = ‘1111,2222’;

Maybe this cause your result.

Also why not to use CDbCriteria features?

    $criteria = new CDbCriteria;

    $criteria->addInCondition('person_id', array('1111','2222'));

    $TransferObject = MTransfer::model()->findAll($criteria);

seb is right… didn’t see the two dots for the parameter settting