I have the following query:
$qb = $this->em->createQueryBuilder()
->select(array('p','c' ,'sc'))
->from('Project\Entity\Product', 'p')
->innerJoin("p.category", "c")
->innerJoin("p.subcategory", "sc")
->where("p.available != 0")
->orderBy("p.create_date")
->addOrderBy("p.id")
->setMaxResults($limit);
In a result I would like to get only Products with id’s of related entities (category and subcategory).
How can I achieve that?
I’m afraid you can’t do that.
Either you use fetch joins and obtain fully loaded objects or load just the object and obtain an uninitialized collection (which requires one more query to be initialized).