I have a query in which I’m joining a number of tables to my original Person entity. A Person
may have multiple Child
relations (OneToMany), and a Child
may have a School
they go to (ManyToOne). Problem is, I don’t need the entire School
entity that connects to each child, only their id
, which is already stored on Child
.
I’m using a Paginator
to iterate through the results and I use HYDRATE_ARRAY to reduce overhead of the ORM parsing data to entity objects. But the id
fields of unfetched relations are not returned this way, and thus, the School id
isn’t either.
I may join the School
entity too, but since the identity is already stored on the Child
records, I don’t see why I should further reduce performance by having the database join another table. Fetching results as entity objects would also solve the problem, but also at the cost of performance. How can I get the id
to apper the results without having to unnecessarily join the the School
entity or having to hydrate the results as objects?
$ query = $ em->getRepository(Entity\Person::class)->createQueryBuilder('p'); $ query ->select([ 'p as person', 'w.name as workplace_name', 'c', ]) ->leftJoin('p.children', 'c') //Entity\Child ->leftJoin('p.workplace', 'w') //Entity\Company //... ; $ paginator = new Paginator($ query); $ paginator->getQuery() ->setHydrationMode(\Doctrine\ORM\Query::HYDRATE_ARRAY);