Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

findBy with multiple IDs

In my quest to edit data from the inverse side of a ManyToOne - OneToMany relation, and to avoid fetching the whole table's content, I want to fetch data from a list of IDs.

While this would work,

$data=array();
foreach($idList as $id) {
    array_push($data, $em->getRepository(Entity::class)->findBy(array('id', $id)));
}

It would do as many queries as there are IDs. Before making my own query in the repository, I would like to know if it's possible to use multiple IDs with findBy.

If it's possible, how do I do it?

like image 901
Preciel Avatar asked Sep 20 '18 13:09

Preciel


1 Answers

You can do

$em->getRepository(Entity::class)->findBy(array('id' => $idList));
like image 81
Noémi Salaün Avatar answered Nov 16 '22 00:11

Noémi Salaün