具有多个 ID 的 findBy
findBy with multiple IDs
为了从 ManyToOne - OneToMany
关系的反面编辑数据,并且为了避免获取整个 table 的内容,我想从 ID 列表中获取数据。
虽然这可行,
$data=array();
foreach($idList as $id) {
array_push($data, $em->getRepository(Entity::class)->findBy(array('id', $id)));
}
有多少 ID,它就会执行多少查询。
在存储库中进行自己的查询之前,我想知道是否可以使用 findBy
.
的多个 ID
如果可以,我该怎么做?
你可以做到
$em->getRepository(Entity::class)->findBy(array('id' => $idList));
为了从 ManyToOne - OneToMany
关系的反面编辑数据,并且为了避免获取整个 table 的内容,我想从 ID 列表中获取数据。
虽然这可行,
$data=array();
foreach($idList as $id) {
array_push($data, $em->getRepository(Entity::class)->findBy(array('id', $id)));
}
有多少 ID,它就会执行多少查询。
在存储库中进行自己的查询之前,我想知道是否可以使用 findBy
.
如果可以,我该怎么做?
你可以做到
$em->getRepository(Entity::class)->findBy(array('id' => $idList));