Because field_sql_storage_field_storage_query uses INNER JOINs instead of LEFT JOINs, any condition on a field's column excludes entities with a NULL value for this column

Because of this, using the "NOT IN" operator in EntityFieldQuery::fieldCondition restricts the results to only the entities with a value for the field. For instance, on an SQL field storage the following query will only return the nodes with a least one tag but not one in $tids. It will not return node without any tag.

$results = $query->entityCondition('entity_type', 'node')
  ->fieldCondition('field_tags', 'tid', $tids, 'NOT IN')
  ->execute();

Comments

pbuyle’s picture

The INNER JOINs in field_sql_storage_field_storage_query are also the cause of #1226622: EntityFieldQuery doesn't support query for entities without a value for a specific field

drewish’s picture

Total bummer that this doesn't work. Huge wart on an otherwise great bit of functionality.

bxtaylor’s picture

Cross posting from #1611438: fieldOrderBy filters out results with empty field values

field_sql_storage_field_storage_query() also excludes items when using fieldOrderBy() and the field is NULL.

pbuyle’s picture

Since #1611438: fieldOrderBy filters out results with empty field values has been closed as "work as designed", I guess the field_sql_storage_field_storage_query works as designed here too (for performances reasons). If right, this issue should either be changed to a feature request or closed (and a feature request should be reported if wanted).

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.