Hello Marco,
I did search on stackoverflow too, but I don't see how can I solve this 
problem with subqueries.
You provide a way to reduce the items by filtering them with subclasses 
properties.
What I want is adding a subclass relation to my final result. 
(e.codedTexts).
I know in native SQL this should be something like : 
SELECT *
FROM result R
LEFT JOIN element E ON E.id = R.element_id
LEFT JOIN codedtext C ON C.element_id = E.id
WHERE E.discriminator = 'codedText' AND R.id = 
'282c4878-d189-4cec-b354-3d94810814ef'

But then I have to map this query to my entities.
I try with the ResultSetMappingBuilder approach without success.

Le mardi 23 septembre 2014 00:39:07 UTC+2, Marco Pivetta a écrit :
>
> Hello,
>
> On 22 September 2014 11:38, Julien Goux <[email protected] 
> <javascript:>> wrote:
>
> Hello,
>> I know this problem has already been discussed, but I can't find any 
>> solution to my problem.
>> I use single table inheritance on my Element entity (abstract class).
>> Element entity has two concrete implementation : CodedTextElement and 
>> NumericElement.
>> The CodedTextElement has a oneToMany relationship with CodedText entity.
>>
>> In top of it, I have a Result entity which contains one Element (could be 
>> NumericElement or CodedTextElement).
>> Now I need to retrieve a Result with its TextCodedElement and its 
>> associated CodedTexts.
>> Here is my query :
>>
>>         $queryBuilder = $this->_em->createQueryBuilder();
>>         $queryBuilder
>>             ->select('res', 'e', 'c')
>>             ->from('Domain\Model\Result', 'res')
>>             ->leftJoin('res.element', 'e')
>>             ->leftJoin('e.codedTexts', 'c')
>>             ->where('e INSTANCE OF Domain\Model\CodedTextElement AND res.id 
>> = :id')
>>             ->setParameter('id', $id);
>>         return $queryBuilder->getQuery()->getOneOrNullResult();
>>
>>
>>
>> As expected, Doctrine throws an error on the e.codedTexts association 
>> which is not defined on Element (but on CodedTextElement).
>> How can I rewrite this query to achieve what I want ? :/
>>
>
> Did you already check stackoverflow? I pretty much replied to this 
> question in http://stackoverflow.com/a/14854067/347063
>
> Marco Pivetta 
>
> http://twitter.com/Ocramius      
>
> http://ocramius.github.com/ 
>

-- 
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