John Smith
John Smith

Reputation: 6207

Doctrine left joins but wont get the fields of 2nd table, why?

for example, I have this:

$this->createQueryBuilder('x')->select()->join('x.coupons', 'c')->getQuery()->getResult()

there are user-s and their coupon-s. This do joins the coupons table but wont select its fields. If I refer to ->getCoupons(), it will make an other select. Is there any workaround for this?

Upvotes: 0

Views: 26

Answers (1)

Paweł Mikołajczuk
Paweł Mikołajczuk

Reputation: 3822

Change your query builder to this:

$this->createQueryBuilder('x')
    ->select('x', 'c')
    ->join('x.coupons', 'c')
    ->getQuery()
    ->getResult()

Upvotes: 1

Related Questions