问题
I need to grab many entities by values in array.
Method bellow:
$arrayOfIds = [1,2,3,4,5];
$I->grabEntitiesFromRepository(Product::class, ['id' => $arrayOfIds]);
Return:
[Doctrine\DBAL\Exception\SyntaxErrorException] An exception occurred while executing 'SELECT p0_.id AS id_2, p0_.created_at AS created_at_3, p0_.updated_at AS updated_at_4 FROM product p0_ WHERE p0_.id = ?, ?, ?, ?, ?' with params [1, 2, 3, 4, 5]:
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 ', 2, 3, 4, 5' at line 1
回答1:
This is a way to do it:
$arrayOfIds = [1,2,3,4,5];
$products = array();
foreach($arrayOfIds as $id){
$products = array_merge($products, $I->grabEntitiesFromRepository(Product::class, ['id' => $id]));
}
$products keeps on adding new products by all IDs.
来源:https://stackoverflow.com/questions/53828401/codeception-how-to-grab-entities-by-values-in-array