phpsymfonydoctrine-ormsymfony-3.4

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?


Solution

  • You can do

    $em->getRepository(Entity::class)->findBy(array('id' => $idList));