A possible workaround but Person is not loaded.
select p from PetAppCoreBundle:Pet p left join p.litter l left join l.producers prod where prod.id in (select pers.id from PetAppCoreBundle:Person k where pers.firstname like '%John%')" Better idea ? Le samedi 18 janvier 2014 21:25:46 UTC+1, David R a écrit : > > It seems not possible : > > > http://stackoverflow.com/questions/8496621/doctrine-dql-class-table-inheritance-and-access-to-subclass-fields > > > Le samedi 18 janvier 2014 21:23:05 UTC+1, David R a écrit : >> >> Thank you for you reply but I don't want do lazy loading. I need to >> retrieve all information in 1 request. >> >> select p from PetAppCoreBundle:Pet p left join p.litter l left join >> l.producers prod where ?? >> => producer is abstract Party Entity (with discriminator) >> - Person extend Party >> - Kennel extend Party >> >> I want to do a where on subtype (Person.firstname). >> where ?? => how to precise table subtype ? >> >> >> Le samedi 18 janvier 2014 12:01:14 UTC+1, Jàπ (Jasper N. Brouwer) a >> écrit : >>> >>> > How to do a where condition on person.firstname = 'John' ? >>> >>> Because $firstname is a property on Person, not on Party (nor Kennel), >>> you actually only want to fetch Person entities. You could write the query >>> as follows: >>> >>> SELECT p FROM PetAppCoreBundle:Person P WHERE p.firstname = >>> :firstname >>> >>> -- >>> Jasper N. Brouwer >>> (@jaspernbrouwer) >>> >>> >>> On 18 Jan 2014, at 11:09, David R <[email protected]> wrote: >>> >>> > Hello, >>> > >>> > I have the following Joined Inheritance configuration : >>> > >>> > /** >>> >>> >>> > * @ORM\Entity >>> >>> >>> > * @ORM\Table("party") >>> >>> >>> > * @ORM\InheritanceType("JOINED") >>> >>> >>> > * @ORM\DiscriminatorColumn(name="type", type="string") >>> >>> >>> > * @ORM\DiscriminatorMap({"person" = "Person", "kennel" = "Kennel"}) >>> >>> >>> > * >>> @ORM\Entity(repositoryClass="PetApp\CoreBundle\Entity\PartyRepository") >>> >>> >>> > */ >>> > abstract class Party >>> > { >>> > ... >>> > } >>> > >>> > >>> > /** >>> >>> >>> > * Person >>> >>> >>> > * >>> >>> >>> > * @ORM\Table("person") >>> >>> >>> > * @ORM\Entity >>> >>> >>> > * >>> @ORM\Entity(repositoryClass="PetApp\CoreBundle\Entity\PersonRepository") >>> >>> >>> > */ >>> > class Person extends Party >>> > { >>> > firstname; >>> > ... >>> > } >>> > >>> > >>> > /** >>> >>> >>> > * Kennel >>> >>> >>> > * >>> >>> >>> > * @ORM\Table("kennel") >>> >>> >>> > * @ORM\Entity >>> >>> >>> > * >>> @ORM\Entity(repositoryClass="PetApp\CoreBundle\Entity\KennelRepository") >>> >>> >>> > */ >>> > class Kennel extends Party >>> > { >>> > name; >>> > } >>> > >>> > >>> > With query builder if I join with abstract entity, I can see in >>> Symfony profiler that ORM executed 2 supplementary left join to resolve >>> inheritance. >>> > That's correct, but how to add where condition on subtype ? >>> > Example : How to do a where condition on person.firstname = 'John' ? >>> > >>> > Query builder : >>> > $qb = $this->createQueryBuilder('p') >>> > ->leftJoin('p.litter', 'l') >>> > ->addSelect('l') >>> > ->leftJoin('l.producers', 'prod') >>> > ->addSelect('prod') >>> > ->where('p.name LIKE :term')->setParameter('term', >>> '%'.$term.'%') >>> > >>> > >>> > SELECT >>> > >>> > >>> > p0_.id AS id0, >>> > >>> > >>> > p0_.name AS name1, >>> > >>> > >>> > p0_.gender AS gender2, >>> > >>> > >>> > p0_.chip AS chip3, >>> > >>> > >>> > p0_.tatoo AS tatoo4, >>> > >>> > >>> > p0_.lof AS lof5, >>> > >>> > >>> > p0_.death AS death6, >>> > >>> > >>> > l1_.id AS id7, >>> > >>> > >>> > l1_.name AS name8, >>> > >>> > >>> > l1_.birth AS birth9, >>> > >>> > >>> > p2_.id AS id10, >>> > >>> > >>> > p3_.firstname AS firstname11, >>> > >>> > >>> > p3_.lastname AS lastname12, >>> > >>> > >>> > k4_.name AS name13, >>> > >>> > >>> > p0_.type_id AS type_id14, >>> > >>> > >>> > p0_.color_id AS color_id15, >>> > >>> > >>> > p0_.litter_id AS litter_id16, >>> > >>> > >>> > l1_.sire_id AS sire_id17, >>> > >>> > >>> > l1_.dam_id AS dam_id18, >>> > >>> > >>> > p2_.type AS type19 >>> > >>> > >>> > FROM >>> > >>> > >>> > pet p0_ >>> > >>> > >>> > LEFT JOIN litter l1_ ON p0_.litter_id = l1_.id >>> > >>> > >>> > LEFT JOIN producers p5_ ON l1_.id = p5_.litter_id >>> > >>> > >>> > LEFT JOIN party p2_ ON p2_.id = p5_.party_id >>> > >>> > >>> > LEFT JOIN person p3_ ON p2_.id = p3_.id >>> > >>> > >>> > LEFT JOIN kennel k4_ ON p2_.id = k4_.id >>> > >>> > >>> > WHERE >>> > >>> > >>> > p0_.name LIKE ? >>> > >>> > Should I use DBAL directly with my own SQL request to resolve this >>> issue ? >>> > >>> > Help appreciate. >>> > Thanks >>> > David. >>> > >>> > >>> > -- >>> > 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/groups/opt_out. >>> >>> -- 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/groups/opt_out.
