0

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!

1
  • Can you not use the array hydrator for that? Commented Jun 6, 2013 at 21:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.