Codeception how to grab entities by values in array

我只是一个虾纸丫 提交于 2019-12-11 19:16:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!