Делаю выборку из бд (здесь только часть кода, при выполнении которого возникает ошибка)
if(count($rgColl) > 0){
$this->projects->join('object_collection', function($join) use($rgColl){
$join->on('object_collection.object_id', '=', 'objects.id');
if(count($rgColl) == 1){
$join->where('object_collection.collection_id', '=', $rgColl[0]);
} else {
$join->whereIn('object_collection.collection_id', $rgColl);
}
});
$this->select[] = 'object_collection.object_id';
$this->select[] = 'object_collection.collection_id';
$this->group[] = 'object_collection.object_id';
}
Если в $rgColl 1 элемент, то все ок, результат возвращается нормально,
если выполняется конструкция $join->whereIn('object_collection.collection_id', $rgColl);
выдает ошибку
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? where `objects`.`category_id` = ? group by `object_parameters_size`.`object_id' at line 1
Беру код запроса сгенерированный ларой, и просто выполню его в MySQL Workbench, все круто, данные возвращаются
Полный запрос выглядит так
SELECT
`objects`.`id`,
`objects`.`ord`,
`objects`.`title`,
`objects`.`art`,
`objects`.`code`,
`object_parameters_size`.`object_id`,
`object_parameters_size`.`parameter_id`,
`object_parameters_size`.`valint`,
`object_collection`.`object_id`,
`object_collection`.`collection_id`
FROM
`objects`
INNER JOIN `object_parameters` AS `object_parameters_size` ON `object_parameters_size`.`object_id` = `objects`.`id`
AND `object_parameters_size`.`parameter_id` = 1
AND `object_parameters_size`.`valint` > 0
AND `object_parameters_size`.`valint` < 500
INNER JOIN `object_collection` ON `object_collection`.`object_id` = `objects`.`id`
AND `object_collection`.`collection_id` IN (38,15,39,40,41)
WHERE
`objects`.`category_id` = 1
GROUP BY `object_parameters_size`.`object_id` , `object_collection`.`object_id`
ORDER BY `objects`.`ord` ASC
Аномалия какая-то получается.