DDC-2780: IS [NOT] NULL conditions with JOINs #3474

Closed
opened 2026-01-22 14:20:33 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 6, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user maryo:

<?php When trying to apply a [NOT] NULL condition on LEFT JOINed association. It ends with an error. "Cannot add having condition on a non result variable." $queryBuilder ->leftJoin('r.players', 'players', 'WITH', 'players = :player') ->where('players IS NULL'); It was working 3 month ago. But then, this commit broke it. d9c1782a4f Or in other words if this is not a bug. How to test if the collection does not contain let's say a user with ID 5 (AND XX OR YY) with DQL/queryBuilder API? IN SQL I would just simply LEFT JOIN it with ON condition and then i would test it for existence using IS NULL in WHERE condition. How to do this using DQL when the pasted example ends with an error?
Originally created by @doctrinebot on GitHub (Nov 6, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user maryo: <?php When trying to apply a [NOT] NULL condition on LEFT JOINed association. It ends with an error. "Cannot add having condition on a non result variable." $queryBuilder ->leftJoin('r.players', 'players', 'WITH', 'players = :player') ->where('players IS NULL'); It was working 3 month ago. But then, this commit broke it. https://github.com/doctrine/doctrine2/commit/d9c1782a4f6d46f66e9deb2c375830f9192d4482 Or in other words if this is not a bug. How to test if the collection does not contain let's say a user with ID 5 (AND XX OR YY) with DQL/queryBuilder API? IN SQL I would just simply LEFT JOIN it with ON condition and then i would test it for existence using IS NULL in WHERE condition. How to do this using DQL when the pasted example ends with an error?
admin added the Bug label 2026-01-22 14:20:33 +01:00
admin closed this issue 2026-01-22 14:20:33 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 30, 2014):

Comment created by maryo:

OK. players.id IS NULL (but it's uglier)

@doctrinebot commented on GitHub (Mar 30, 2014): Comment created by maryo: OK. players.id IS NULL (but it's uglier)
Author
Owner

@doctrinebot commented on GitHub (Apr 14, 2015):

Comment created by Soullivaneuh:

r.players IS NULL works too.

But I don't understand why this will be not fixed. I agree, it's uglier.

@doctrinebot commented on GitHub (Apr 14, 2015): Comment created by Soullivaneuh: `r.players IS NULL` works too. But I don't understand why this will be not fixed. I agree, it's uglier.
Author
Owner

@doctrinebot commented on GitHub (Jul 2, 2015):

Comment created by maryo:

I am checking the activity and it looks It was me who changed it to "Won't fix". If it's true then it was an accident. Sorry if I'm wrong.

@doctrinebot commented on GitHub (Jul 2, 2015): Comment created by maryo: I am checking the activity and it looks It was me who changed it to "Won't fix". If it's true then it was an accident. Sorry if I'm wrong.
Author
Owner

@doctrinebot commented on GitHub (Jul 16, 2015):

Comment created by pejot:

Hi,

also experiencing this error. Worked fine with 2.4.7, now trying to migrate to 2.5.0 and getting this error. The problem is, even when I do select the variable to SELECT, still getting the error.

@doctrinebot commented on GitHub (Jul 16, 2015): Comment created by pejot: Hi, also experiencing this error. Worked fine with 2.4.7, now trying to migrate to 2.5.0 and getting this error. The problem is, even when I do select the variable to SELECT, still getting the error.
Author
Owner

@doctrinebot commented on GitHub (Jul 31, 2015):

Comment created by mrthehud:

I'm seeing this too - but I actually think the "players.id IS NULL" is right - otherwise what you're really asking for is something like "COUNT(r.players) == 0" - which might cause problems when you combine the query with pagination (for instance, using the KNP Paginator in Symfony).

@doctrinebot commented on GitHub (Jul 31, 2015): Comment created by mrthehud: I'm seeing this too - but I actually think the "players.id IS NULL" is right - otherwise what you're really asking for is something like "COUNT(r.players) == 0" - which might cause problems when you combine the query with pagination (for instance, using the KNP Paginator in Symfony).
Author
Owner

@doctrinebot commented on GitHub (Oct 6, 2015):

Comment created by benjamin:

Still no updates on this bug, two years after? I'm surprised that a potential bug introduced by a commit is left without any comment from the core team for so long.

@doctrinebot commented on GitHub (Oct 6, 2015): Comment created by benjamin: Still no updates on this bug, two years after? I'm surprised that a potential bug introduced by a commit is left without any comment from the core team for so long.
Author
Owner

@kipelovets commented on GitHub (May 10, 2016):

Any news on this?

@kipelovets commented on GitHub (May 10, 2016): Any news on this?
Author
Owner

@pdrosos commented on GitHub (Dec 19, 2016):

Any news here?

@pdrosos commented on GitHub (Dec 19, 2016): Any news here?
Author
Owner

@fprochazka commented on GitHub (Dec 22, 2016):

There is probably a reason the exception was added. IMHO it would be helpful, if someone proved that #5680 solves it. Otherwise the maintainers have to do it, which means they can do it only when they have the time for it.

@fprochazka commented on GitHub (Dec 22, 2016): There is probably a reason the exception was added. IMHO it would be helpful, if someone proved that #5680 solves it. Otherwise the maintainers have to do it, which means they can do it only when they have the time for it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3474