Here is the content of my custom repository function for my entity Feed.
return $this->createQueryBuilder('f')
->select('f, COUNT(s)')
->leftJoin('f.subscriptions','s')
->groupBy('f')
->having('f.inCatalog = TRUE')
->orHaving('COUNT(s) > 0');
->getQuery()->getResult();
I want to get every feed with at least one subscription in my catalog, then browse it in a foreach loop but it returns this :
FatalErrorException: Error: Call to a member function getId() on a non-object in * line *
Any idea how to solve this problem ?
I saw you could do, for example, $feed[0]->getId() but I want an object, not an array.
Some topics are similar but I didn't find any good answer.
EDIT : Well, i think i found the answer to my own question...
To get what i want, i need to remove the COUNT() in the select. I don't want it and it is only needed in the HAVING.
This looks to be working :
return $this->createQueryBuilder('f')
->leftJoin('f.subscriptions','s')
->groupBy('f')
->having('f.inCatalog = TRUE')
->orHaving('COUNT(s) > 0');
->getQuery()->getResult();
Now the result returns an array of objects as i wanted. Thanks to the people who answered.
->select('COUNT(s.id)')?