Yes, that is correct.
On Sunday, 4 May 2014 19:48:47 UTC+2, spezia wrote:
>
> If I understand,
> when we call only ->select('p'), and then $post->getUser(); we have 2
> queries to the database.
> But, if we put ->select('p, u')->from(..., 'p')->join(..,'u'), then we
> have only one query to database (we will return all data via one query),
> when we call $post->getUser();
> So, if we plan to use users, then we will put ->select('p, u')->join('u')..,
> , because this is better way. Correct?
>
> недеља, 04. мај 2014. 17.35.30 UTC+2, Marco Pivetta је написао/ла:
>>
>> 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.