8

After some searching the closest code snippet I've found is:

->fieldCondition('field_name_ref', 'nid', 'NULL', '!=');

This will find everything where the node reference is not null. But if I change the != to = it returns nothing. I've tried all the combinations of values I can think of:

  • Passing in NULL instead of 'NULL'.
  • Passing in array()
  • Trying 1, "<"
  • "", "CONTAINS"
  • "", "="
  • 0, "="

Plus a few more, just trying all the combinations I can think of.

How can I pull this off?

2 Answers 2

7

As crazy as it might sound, you can't. Normally you'd use the IS NULL operator to do this but it is apparently not supported by EntityFieldQuery:

EntityFieldQuery does not support isNull or isNotNull

Also I think the EntityFieldQuery internally uses INNER JOIN, rather than LEFT JOIN so records that don't have a value in your condition table would be excluded from the query results anyway. The issue has been reported several times:

3
  • I ended up using this: drupal.org/node/1226622#comment-6809826 Thanks!
    – mikeytown2
    Commented Jan 31, 2013 at 0:09
  • I think this was your very 1st answer on Drupal.SE ... +1 now, about 4 years later ... And congratulations for hitting the 100 K rep !!! Commented Sep 10, 2015 at 20:55
  • Cheers @Pierre.Vriens, apparently I get a t-shirt ;)
    – Clive
    Commented Sep 11, 2015 at 18:21
5

For a workaround I added a custom tag to the query and then I used hook_query_TAG_alter(), see #1157006 at drupal.org for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.