Doctrine DQL, class table inheritance and access to subclass fields

前端 未结 5 490
萌比男神i
萌比男神i 2020-12-29 06:15

I have a problem with a DQL query and entity specialization.

I have an Entity called Auction, which is OneToOne relation with Item

5条回答
  •  别那么骄傲
    2020-12-29 06:48

    You can easily solve this by left-joining your base entity with your inheritance class using the id:

    SELECT a FROM Entities\Auction a
        INNER JOIN a.item i 
        INNER JOIN Entities\Book b WITH b.id = i.id 
        INNER JOIN b.bookTypes bt
        WHERE bt.type = 'Fantasy' 
        AND...
    

    or with a queryBuilder:

    $queryBuilderb->select('a')
       ->from('Entities\Auction', 'a')
       ->innerJoin('a.item', 'i')
       ->innerJoin('Entities\Book', 'b', 'WITH', 'b.id = i.id')
       ->innerJoin('b.bookTypes', 'bt')
       ->where('bt.type = :type')
       ->andWhere(...
       ->setParameter('type', 'Fantasy');
    

    This is based on the answer given by Ian Philips in the question here

提交回复
热议问题