Doctrine 2 - How to use discriminator column in where clause

后端 未结 5 1745
春和景丽
春和景丽 2020-12-14 05:45

I was used discriminator column in where clause like this:

//f = root entity
$qb = $this->createQueryBuilder(\'f\');
$qb->add(\'where\', \'f.format = \         


        
5条回答
  •  萌比男神i
    2020-12-14 06:28

    As this latest doctrine version it is supported to query directly the discriminator value.

    public function findOfType($discr)
        {
            $qb = $this->createQueryBuilder('e');
            $qb->where('e INSTANCE OF :discr');
            $qb->setParameter('discr', $discr);
            return $qb->getQuery()->getResult();
        }
    

    will have a result query with this clause:

    WHERE e0_.discr IN ('discriminator_passed_to_function')
    

提交回复
热议问题