Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
entity system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Jul 2011 at 12:43 UTC
Updated:
5 Nov 2017 at 19:29 UTC
Jump to comment: Most recent
Comments
Comment #1
marcingy commentedMoving to normal, as this is not a major issue and also pushing to 8.x as we fix in head first.
Comment #2
jbrown commentedsubscribing
Comment #3
pbuyle commented#1236748: EntityFieldQuery doesn't support query for entities without a value for a specific field duplicates this issue.
Querying for
NULLvalue for field is not supported byfield_sql_storage_field_storage_querybecause it usesINNER JOINs instead ofLEFT JOINs. I don't known if any other field storage backend supportNULLin field condition or not.These
INNER JOINs are also the cause of #1240566: In field_sql_storage_field_storage_query, any condition on a field's column excludes entities with a NULL value for this column.Comment #4
pbuyle commentedComment #5
adriaanm commentedsubscribing
Comment #6
zilverdistel commentedsubscribing
In the meantime, is there any other way to do this?
Comment #7
grota commentedFor a workaround see #1157006.
Comment #8
rogical commented#1157006 is very interesting, but only can be used on tags, while this feature is very important in other entity queries.
Hope see to get passed soon and backport to D7.
Comment #9
DizzyC commentedI worked around this by extending the EntityFieldQuery class and implementing some custom logic but it would be nice if a solution to this would make it into D8 and hopefully be ported back to D7.
You can just override the finishQuery method that receives the SelectQuery as the first parameter and add custom logic to it.
Comment #10
bxtaylor commentedCross 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.
#9 looks promising and will give that a go.
Comment #11
chx commented#1611438: fieldOrderBy filters out results with empty field values
Comment #12
pbuyle commentedKnowing this issue but not #1611438: fieldOrderBy filters out results with empty field values, it's hard to see how this is a duplicate. Would someone provide a brief explanation.
Since #1611438: fieldOrderBy filters out results with empty field values has been closed as "work as designed" spawning a new feature request at #1662942: Make EntityFieldQuery::fieldOrderBy include NULL field values, should we open a new feature request if we want to be able to query for entities without a value for a specific field?
Comment #13
dalinFor folks that are looking for an easier way to do this in D7 try something like this:
Comment #14
andrewkamm commentedThanks for the
EntityFieldQueryForNullFieldscode @dalin, it saved me a lot of work.Comment #15
mikeytown2 commented#13 is a great solution.
reset(array_keys(...))does throw a strict warning though.This is how I'm using it. I need a value from a field if another field is empty.
http://drupal.stackexchange.com/questions/18093/get-only-some-fields-wit...
Usage
Comment #16
i.bajrai commentedUsing #13 or #15 gives me:
PDOException: SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'LEFT OUTER JOIN field_data_field_latitude field_data_field_latitude0 INNER JOIN '
at line 1: SELECT field_data_field_latitude0.entity_type AS entity_type, field_data_field_latitude0.entity_id AS entity_id, field_data_field_latitude0.revision_id AS revision_id, field_data_field_latitude0.bundle AS bundle
FROM LEFT OUTER JOIN {field_data_field_latitude} field_data_field_latitude0
INNER JOIN {node} node ON node.nid = field_data_field_latitude0.entity_id
WHERE (field_data_field_latitude0.field_latitude_value IS NULL )
AND (field_data_field_latitude0.deleted = :db_condition_placeholder_0)
AND (node.type = :db_condition_placeholder_1) AND (field_data_field_latitude0.entity_type = :db_condition_placeholder_2) ;
Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => delivery [:db_condition_placeholder_2] => node )
in field_sql_storage_field_storage_query()
(line 582 of /modules/field/modules/field_sql_storage/field_sql_storage.module).
Comment #17
nick_vhImproved it a little bit :
Some code above was executed too many times. I'm thinking in integrating this in efq_extra_fields.
Comment #18
donquixote commentedThis is still not ideal.
For me, EntityFieldQuery will put the tables in a weird order. Instead of putting the entity table first it puts some field first and then the entity.
As a result, the field table has neither a join type nor a join condition, whereas the entity table does have.
I don't want to make the entity table the "LEFT JOIN" one..
Comment #19
mikeytown2 commentedAfter a bunch of testing I created a sandbox to hold the EFQ stuff
https://drupal.org/sandbox/mikeytown2/2209909
http://drupalcode.org/sandbox/mikeytown2/2209909.git/blob/HEAD:/entityfi...
Instead of addExtraField I have getFieldValue & getPropertyValue. getFieldValue by default does a LEFT JOIN but it can be changed to INNER if needed.
Comment #20
calebtr commentedRe #16, I had the same issue.
The issue is that the query ends up being written as "SELECT ... FROM LEFT OUTER JOIN ...". The extended EFQ class needs another table to query before joining in the one you want to get null data from.
Add another field to your query before the null one - the documentation from #13 could be:
So I'm intentionally slowing down this query by adding in an unnecessary JOIN as a workaround, which gives me a sense of why this fix can't simply be added to EntityFieldQuery.
Also, if anyone is looking for it, the open issue is at https://drupal.org/node/1226622; I'm pasting the udpate to the documentation here because this is where the snippet is.
Comment #21
sinasalek commentedWhen a field tables are empty that field cannot be used on field Condition because result won't be filtered by it. This is an unexpected behavior and can cause security issues.
Comment #22
rosk0Comment #23
useernamee commentedSo, what should be the arguments of fieldCondition when searching for nodes that have certain field NULL.
->fieldCondition('field_snode_reference', 'value', NULL, 'IS NULL')does not work for me.
Regards and thanks
kireli