9

Hi I'm having trouble with what I thought would be an easy task.

I am retrieving a post from the database. The Post entity has a field createdBy which is associated to a User entity.

What I would like to do is load Post and User with two separate queries (no join). That means I need to have access to the created_by foreign key integer on the $post object. Doctrine does not seem to expose that at all. A var_dump of post shows createdBy => null. If I join the user on directly in the post query createdBy => User object. Is there no way to get the created_by foreign key integer from post so I can query for the user?

Thanks

1 Answer 1

20

Use this on your query:

$q->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true); $q->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); 

Hydratation is disabled, so you have your result as an array.

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

2 Comments

Ah great. Hadn't known about that hint. However there does not seem to be a setHydrate method on the query object. You can just hydrate it as an array though and it works (and you still get a nicely hydrated result). $q->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); If you update your answer I'll accept it. Thanks!
I actually just decided to give the MongoDB ODM a try so I'll keep that in mind. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.