Preciel
Preciel

Reputation: 2827

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?

Upvotes: 35

Views: 30802

Answers (1)

Noémi Salaün
Noémi Salaün

Reputation: 5026

You can do

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

Upvotes: 69

Related Questions