我需要根据数组中的值获取许多实体。
方法:
$arrayOfIds = [1,2,3,4,5]; $I->grabEntitiesFromRepository(Product::class, ['id' => $arrayOfIds]);
返回:
[条令\dbal\exception\syntaxErrorException]发生异常 执行“select p0”时 作为id_2,p0_.created_at as created_at_3,p0_.updated_at as 从产品p0_u更新到产品p0_u,其中p0_u.id=?????具有 参数[1,2,3,4,5]: sqlstate[42000]:语法错误或访问冲突:1064 SQL语法错误;请查看与您的 mysql服务器版本,用于正确的语法使用near',2,3,4,5' 在第1行
[条令\dbal\exception\syntaxErrorException]发生异常 执行“select p0”时 作为id_2,p0_.created_at as created_at_3,p0_.updated_at as 从产品p0_u更新到产品p0_u,其中p0_u.id=?????具有 参数[1,2,3,4,5]:
sqlstate[42000]:语法错误或访问冲突:1064 SQL语法错误;请查看与您的 mysql服务器版本,用于正确的语法使用near',2,3,4,5' 在第1行
这是一种方法:
$arrayOfIds = [1,2,3,4,5]; $products = array(); foreach($arrayOfIds as $id){ $products = array_merge($products, $I->grabEntitiesFromRepository(Product::class, ['id' => $id])); }
$products继续按所有ID添加新产品。