"LEFT JOIN" with "WHERE" - "WHERE" appearing in SQL as ON instead of WHERE #5181

Closed
opened 2026-01-22 15:00:55 +01:00 by admin · 1 comment
Owner

Originally created by @audoh on GitHub (Jul 7, 2016).

Here's my query:
$query = $qb
->select('p')
->from('PackageBundle:Package', 'p')
->where('p.slug = :slug')
->setParameter('slug', $slug)
->leftJoin('PackageBundle:PackageCategory', 'pc')
->andWhere('pc.slug = :categorySlug')
->setParameter('categorySlug', $categorySlug)
;

Here's the runnable that results from that:
SELECT p0_.id AS id_0, p0_.name AS name_1, p0_.brief AS brief_2, p0_.slug AS slug_3, p0_.package_category_id AS package_category_id_4 FROM package p0_ LEFT JOIN package_category p1_ ON (p0_.slug = 'slammin-sofas' AND p1_.slug = 'hmo-packse');

It still returns the slammin-sofas package despite the category's actual slug being hmo-packs, not hmo-packse. Testing the same SQL query as it should be directly via MySQL (WHERE p0_.slug = 'slammin-sofas' AND p1_.slug = 'hmo-packse') works as it should.

This is with Doctrine 2.4.8 in Symfony 2.8.8 (DoctrineBundle 1.4, I believe).

The order of the builder statements makes no difference (putting andWhere before the leftJoin doesn't change anything).

Originally created by @audoh on GitHub (Jul 7, 2016). Here's my query: `$query = $qb` `->select('p')` `->from('PackageBundle:Package', 'p')` `->where('p.slug = :slug')` `->setParameter('slug', $slug)` `->leftJoin('PackageBundle:PackageCategory', 'pc')` `->andWhere('pc.slug = :categorySlug')` `->setParameter('categorySlug', $categorySlug)` `;` Here's the runnable that results from that: `SELECT p0_.id AS id_0, p0_.name AS name_1, p0_.brief AS brief_2, p0_.slug AS slug_3, p0_.package_category_id AS package_category_id_4 FROM package p0_ LEFT JOIN package_category p1_ ON (p0_.slug = 'slammin-sofas' AND p1_.slug = 'hmo-packse');` It still returns the slammin-sofas package despite the category's actual slug being hmo-packs, not hmo-packse. Testing the same SQL query as it should be directly via MySQL (`WHERE p0_.slug = 'slammin-sofas' AND p1_.slug = 'hmo-packse'`) works as it should. This is with Doctrine 2.4.8 in Symfony 2.8.8 (DoctrineBundle 1.4, I believe). The order of the builder statements makes no difference (putting andWhere before the leftJoin doesn't change anything).
admin added the BugInvalid labels 2026-01-22 15:00:55 +01:00
admin closed this issue 2026-01-22 15:00:55 +01:00
Author
Owner

@audoh commented on GitHub (Jul 7, 2016):

That's my fault, I absentmindedly put the wrong thing in the join. Should've been:
->leftJoin('pc.packageCategory', 'pc')

@audoh commented on GitHub (Jul 7, 2016): That's my fault, I absentmindedly put the wrong thing in the join. Should've been: `->leftJoin('pc.packageCategory', 'pc')`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5181