I have an entity Offer. Offer has a ManyToMany Relationship to Files. Now I want to have all Offers, that have files -> Count(offer.files) > 0.
I tried it like this, but doesn't work:
$this->repository->createQueryBuilder('offer')
->addSelect('COUNT(offer.files) as files')
->having('files > 1')
->getQuery()
->getResult();
Actually you do not need a join. Doctrine has built in SIZE
DQL function for that.
SIZE(collection) - Return the number of elements in the specified collection
So you could use it like this:
$this->repository->createQueryBuilder('offer')
->addSelect('SIZE(offer.files) as files')
->having('files > 1')
->getQuery()
->getResult();
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