How to select discriminator column in doctrine 2

前端 未结 3 1112
长情又很酷
长情又很酷 2020-12-20 17:14

I need some help when select only discriminator column from doctrine 2 when run the DQL below

SELECT p.type FROM AppBundle\\Entity\\Product p
3条回答
  •  情话喂你
    2020-12-20 17:50

    There is no direct access to the discriminator column.

    It may happen that the entities of a special type should be queried. Because there is no direct access to the discriminator column, Doctrine provides the INSTANCE OF construct.

    You can query for the type of your entity using the INSTANCE OF DQL as described in the docs. As example:

    $query = $em->createQuery("SELECT product FROM AppBundle\Entity\AbstractProduct product WHERE product  INSTANCE OF AppBundle\Entity\Product");
    $products = $query->getResult();
    

    Hope this helps

提交回复
热议问题