I was used discriminator column in where clause like this:
//f = root entity
$qb = $this->createQueryBuilder('f');
$qb->add('where', 'f.format = \'image\' OR f.format = \'text\'');
I've got an error: "Message: [Semantical Error] line 0, col 73 near 'format = 'image'': Error: Class Entities\File\AbstractFile has no field or association named format"
How can i use discriminator column in where clause?
Thanks.
I think that you should use INSTANCE OF
It would look in query builder like this:
$class = 'Entity\File\Image';
$qb = $this->createQueryBuilder('f');
$qb->where($qb->expr()->isInstanceOf('f', $class));
Note: that you will not be able to set the class as a parameter because it will be escaped.
for PHP 5.50 and above:
$this->createQueryBuilder('f')
->andWhere('f INSTANCE OF '.Image::class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With