Codeception如何通过数组中的值获取实体 [英] Codeception how to grab entities by values in array

查看:67
本文介绍了Codeception如何通过数组中的值获取实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过数组中的值来获取许多实体。

I need to grab many entities by values in array.

以下方法:

$arrayOfIds = [1,2,3,4,5];
$I->grabEntitiesFromRepository(Product::class, ['id' => $arrayOfIds]);

返回:


[Doctrine\DBAL\Exception\SyntaxErrorException]执行'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 =?,?,?,?,?',带有
参数[1、2、3、4、5]:

[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]:语法错误或访问冲突:1064您的SQL语法中有
错误;否则,可能会出错。检查与您的
MySQL服务器版本相对应的手册,以在第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


推荐答案

这是一种方法:

$arrayOfIds = [1,2,3,4,5];
$products = array();
foreach($arrayOfIds as $id){
   $products = array_merge($products, $I->grabEntitiesFromRepository(Product::class, ['id' => $id]));
}

$ products会按所有ID不断添加新产品。

$products keeps on adding new products by all IDs.

这篇关于Codeception如何通过数组中的值获取实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆