ActiveRecord - param binding with "IN" query

Hi all,

I’m having an issue when trying to do an “IN”-type query using ActiveRecord. Here’s a contrived example:

// This array comes from elsewhere, but for the example's sake looks like:

$generalIssues = array(1, 2, 3, 4, 5);

// Prior to the query, I put the array values into a comma-delimited string:

$generalIssues = implode(',', $generalIssues);

// Execute the query -- note the "IN" part:

$positions = Position::model()->findAll(


		'select'	=> "*",

		'condition'	=> "issue_id IN (:generalIssues)",

		'params'	=> array(':generalIssues' => $generalIssues)



…producing a query like:

[sql]SELECT * FROM position

WHERE issue_id IN (‘1,2,3,4,5’)[/sql]

…note the single-quotes inside the parens - those break the query. I get WHY Yii would do that, but is there a way to prevent it? Or am I going about it the wrong way?

edit: I see the addInCondition() method, but I’d still like to know if this can be done inline, as in my example.


I recommend using addInCondition in this case.

I am having the same problem with the apostrophes. Were you ever able to resolve this?