Hello.
I think that code says better.
$users = Users::find(/* ... */);
// PHP 5.3 sucks
$usersIds = array_map(function ($u) { return $u['id']; }, $users->toArray());
$implodedUsersIds = implode(',', $usersIds);
var_export($usersIds); // Good: array (0 => '5', 1 => '10', 2 => '14', 3 => '328', ...)
$cars1 = Cars::find(array(
'conditions' => "userId IN ($implodedUsersIds)",
));
$cars2 = Cars::find(array(
'conditions' => 'userId IN (:userId:)',
'bind' => array('userId' => $implodedUsersIds)
));
var_export($cars1->count()); // Good : 40
var_export($cars2->count()); // WTF?! : 0
I've looked into database logging – these two SQLs:
SELECT `cars`.* FROM `cars` WHERE `cars`.`userId` IN (5, 10, 14, 328, ...) -- good
SELECT `cars`.* FROM `cars` WHERE `cars`.`userId` IN (:userId) -- bad
What's wrong? Quer for getting users use 'conditions' and 'bind' too and it's ok.