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
Comment #1
pbuyle commentedThe
INNER JOINs infield_sql_storage_field_storage_queryare also the cause of #1226622: EntityFieldQuery doesn't support query for entities without a value for a specific fieldComment #2
drewish commentedTotal bummer that this doesn't work. Huge wart on an otherwise great bit of functionality.
Comment #3
bxtaylor commentedCross posting from #1611438: fieldOrderBy filters out results with empty field values
field_sql_storage_field_storage_query()also excludes items when usingfieldOrderBy()and the field is NULL.Comment #4
pbuyle commentedSince #1611438: fieldOrderBy filters out results with empty field values has been closed as "work as designed", I guess the
field_sql_storage_field_storage_queryworks 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).