It will bite you back, as we will also add an exception for this in the ORM
at some point

On 27 Jun 2017 08:54, "Joshua Wilson" <[email protected]> wrote:

> Lets assume the objects I get back, I do not care to update in the
> request, consider them strictly read only, then does it matter if the data
> is 'corrupted'? If it does not matter, I would like to do it lol.
>
> On Tuesday, June 27, 2017 at 1:14:41 AM UTC-5, Marco Pivetta wrote:
>>
>> You still cannot hydrate a `Bill` object with a subset of `Favorite`
>> instances in it, as that would corrupt the data. You can use the good old
>> SQL-style multi-column result:
>>
>>
>> SELECT f as fav, b as bill FROM Favorite f JOIN f.bill b WHERE f.id IN
>> (SELECT f1.id FROM Bill b JOIN b.favorites f1 WHERE f1.user = :user OR
>> f1.user IS NULL)
>>
>> Marco Pivetta
>>
>> http://twitter.com/Ocramius
>>
>> http://ocramius.github.com/
>>
>> On Tue, Jun 27, 2017 at 8:11 AM, Joshua Wilson <[email protected]> wrote:
>>
>>> That would end up being a problem as I would only see a subset of bills
>>> where as I want the complete list of bills with a subset of favorite, does
>>> that make sense?
>>>
>>> On Tuesday, June 27, 2017 at 1:01:17 AM UTC-5, Marco Pivetta wrote:
>>>>
>>>> That's the same as
>>>>
>>>> SELECT b FROM Bill b LEFT JOIN b.favorites f WHERE f.user = :user OR
>>>> f.user IS NULL
>>>>
>>>> That is a problem, as it will hydrate `Bill` objects with incomplete
>>>> associations.
>>>>
>>>> Turn it around:
>>>>
>>>> SELECT f FROM Favorite f WHERE f.id IN (SELECT f1.id FROM Bill b JOIN
>>>> b.favorites f1 WHERE f1.user = :user OR f1.user IS NULL)
>>>>
>>>>
>>>> Marco Pivetta
>>>>
>>>> http://twitter.com/Ocramius
>>>>
>>>> http://ocramius.github.com/
>>>>
>>>> On Tue, Jun 27, 2017 at 7:58 AM, Joshua Wilson <[email protected]>
>>>> wrote:
>>>>
>>>>> Actaully, based on your first response, I went back at looked at the
>>>>> criteria builder even more and ended up messing around with it and got a
>>>>> working example:
>>>>>
>>>>> $qb = $this->bill_repository->createQueryBuilder('b')
>>>>>     ->leftJoin('b.favorites', 'f');
>>>>>
>>>>> $critera = new Criteria();
>>>>> $critera->where(Criteria::expr()->eq("f.user_id", $user->id));
>>>>> $critera->orWhere(Criteria::expr()->eq("f.user_id", null));
>>>>> $qb->addCriteria($critera);
>>>>>
>>>>>
>>>>> On Tuesday, June 27, 2017 at 12:43:24 AM UTC-5, Marco Pivetta wrote:
>>>>>>
>>>>>>  Could you make a more clear example with your currently entity
>>>>>> definitions? Keep it minimal, but try showing what the expected result
>>>>>> would be like
>>>>>>
>>>>>> Marco Pivetta
>>>>>>
>>>>>> http://twitter.com/Ocramius
>>>>>>
>>>>>> http://ocramius.github.com/
>>>>>>
>>>>>> On Tue, Jun 27, 2017 at 7:40 AM, Joshua Wilson <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> I have but I dont quite understand how to work with it, in an ideal
>>>>>>> world i'd basically like something like...
>>>>>>>
>>>>>>> SELECT a.*, b.* FROM table a LEFT JOIN table b ON b.column =
>>>>>>> a.column WITH b.other_column = 1;
>>>>>>>
>>>>>>> Basically, at the end of the day, I have a table full of items,
>>>>>>> users can favorite those items, but I dont want users to see what each
>>>>>>> other have favorited when I display the list of items, I only want the 
>>>>>>> user
>>>>>>> making the request to be able to see what items they have favorited.
>>>>>>> Granted I can probably loop over the results from the query and check 
>>>>>>> each
>>>>>>> record and mark if it was favorited but I already have a one to many
>>>>>>> relationship setup between items and favorites and it'd be really nice 
>>>>>>> if I
>>>>>>> could just return the single favorite record for the user who is 
>>>>>>> looking at
>>>>>>> the list of items
>>>>>>>
>>>>>>> --
>>>>>>> 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 https://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 https://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 https://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 https://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 https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to