I am looking for a way to tranform my Doctrine 2 entity into an array (including its related objects), in the same way doctrine hydrates to an array.
Does anyone know how to do this?
Thanks!
I am looking for a way to tranform my Doctrine 2 entity into an array (including its related objects), in the same way doctrine hydrates to an array.
Does anyone know how to do this?
Thanks!
I am not sure if you mean this, but i got the desired result by using "fetch joins" and then hydrating:
Fetch Joins: In addition to the uses of regular joins: Used to fetch related entities and include them in the hydrated result of a query.
There is no special DQL keyword that distinguishes a regular join from a fetch join. A join (be it an inner or outer join) becomes a “fetch join” as soon as fields of the joined entity appear in the SELECT part of the DQL query outside of an aggregate function. Otherwise its a “regular join”.
$query = $em->createQuery("SELECT u, a FROM User u JOIN u.address a WHERE a.city = 'Berlin'");
$users = $query->getArrayResult();
http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html