Hi Spezia,

You may want to look at this specific paragraph in the docs:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#joins

In general, the idea is that in DQL you will only ever get back the
so-called "root" of your selection, which in your example is the "p" (Post)
entity.
If you then also select "u, c", (fetch-join) those will be "hydrated" into
"p", and become part of a Post's associations.

It is important to note that you should not filter associations and
fetch-join them, as that will hydrate wrong data into your Post entity.


Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 4 May 2014 17:31, spezia <[email protected]> wrote:

> I am confused about Doctrine. I have the experience with sql.
> I am not sure when to use join, left join methods,..
>
> Example: we have the 3 tables: user, post and comments, and the classic
> connections among them...
>
> 1) Example
>
> $post = ...->select('p')
> ->from('Post p')
> ->getQuery()
> ->getResult();
>
> If I want an user, I can get it: $post->getUser(); or comments:
> $post->getComments();
> I do not need next:
>
> $post = ...->select('p')
> ->from('Post p')
> ->join('p.user', 'u')
> ->join('p.comments', 'c')
> ->getQuery()
> ->getResult();
>
> I get the same result.
> Also I am not sure when I need something like this
> ->select('p, u, c')...
>
> Can someone help me :)
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to