Hi, I'm using entity reference along with entityreference_prepopulate.
I had a look in the code of prepopulate and this just uses entity reference's handler:
// Check if the IDs are valid, and get filter out the ones that are not valid.
$handler = entityreference_get_selection_handler($field, $instance);
$ids = $handler->validateReferencableEntities($ids);
It's that third line that does it.
Am getting the following error. I've re-used this entity reference field across multiple content types.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1)) AND(( (na.gid = :db_condition_placeholder_2) AND (na.realm = :db_condition_placeholder_3) )OR( (na.gid = :db_condition_placeholder_4) AND (na.realm = :db_condition_placeholder_5) )OR( (na.gid = :db_condition_placeholder_6) AND (na.realm = :db_condition_placeholder_7) )OR( (na.gid = :db_condition_placeholder_8) AND (na.realm = :db_condition_placeholder_9) )OR( (na.gid = :db_condition_placeholder_10) AND (na.realm = :db_condition_placeholder_11) )OR( (na.gid = :db_condition_placeholder_12) AND (na.realm = :db_condition_placeholder_13) )OR( (na.gid = :db_condition_placeholder_14) AND (na.realm = :db_condition_placeholder_15) ))AND (na.grant_view >= :db_condition_placeholder_16) ; Array ( [:db_condition_placeholder_0] => 576 [:db_condition_placeholder_1] => pub [:db_condition_placeholder_2] => 0 [:db_condition_placeholder_3] => all [:db_condition_placeholder_4] => 27 [:db_condition_placeholder_5] => content_access_author [:db_condition_placeholder_6] => 2 [:db_condition_placeholder_7] => content_access_rid [:db_condition_placeholder_8] => 11 [:db_condition_placeholder_9] => content_access_rid [:db_condition_placeholder_10] => 27 [:db_condition_placeholder_11] => nodeaccess_userreference [:db_condition_placeholder_12] => 27 [:db_condition_placeholder_13] => nodeaccess_userreference_author [:db_condition_placeholder_14] => 1 [:db_condition_placeholder_15] => nodeaccess_userreference_all [:db_condition_placeholder_16] => 1 [:entity_type] => node ) in EntityFieldQuery->execute() (line 1136 of /var/www/vhosts/*/httpdocs/includes/entity.inc).
Comments
Comment #0.0
heylookalive commentedRemoved dev site url
Comment #1
heylookalive commentedAm also using nodeaccess_userreference, I turned this off and the error reduced a bit, but persists. Hopefully this should be clearer to debug:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1)) AND(( (na.gid = :db_condition_placeholder_2) AND (na.realm = :db_condition_placeholder_3) )OR( (na.gid = :db_condition_placeholder_4) AND (na.realm = :db_condition_placeholder_5) )OR( (na.gid = :db_condition_placeholder_6) AND (na.realm = :db_condition_placeholder_7) )OR( (na.gid = :db_condition_placeholder_8) AND (na.realm = :db_condition_placeholder_9) ))AND (na.grant_view >= :db_condition_placeholder_10) ; Array ( [:db_condition_placeholder_0] => 576 [:db_condition_placeholder_1] => pub [:db_condition_placeholder_2] => 0 [:db_condition_placeholder_3] => all [:db_condition_placeholder_4] => 27 [:db_condition_placeholder_5] => content_access_author [:db_condition_placeholder_6] => 2 [:db_condition_placeholder_7] => content_access_rid [:db_condition_placeholder_8] => 11 [:db_condition_placeholder_9] => content_access_rid [:db_condition_placeholder_10] => 1 [:entity_type] => node ) in EntityFieldQuery->execute() (line 1136 of /var/www/vhosts/sn.deeson.net/httpdocs/includes/entity.inc).Comment #2
heylookalive commentedOK, this seems to be related to access issues. We've got content_access module installed.
Commenting out the following line in stops the error (but somehow commenting out access related stuff seems like a bad idea :) :
entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php
Line 196
Comment #3
Fred75 commentedHello,
I have the very same problem, with Prepopulate and Content Access installed.
I think those threads tackle similar problems:
... But I am not competent enough to use the information there... so a fix to the module and/or core would be really welcome. :)
Cheers,
F.
Comment #4
strellman commentedWe have this problem using OG and i18n for a multilingual environment.
We are not using nodereference or content access. We needed entityreference for og_group_ref
Wow its really tough to uninstall OG now.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1)) AND (node.language IN (:db_condition_placeholder_2, :db_condition_placeholder_3)) AND(( (na.gid = :db_condition_placeholder_4) AND (na.realm = :db_condition_placeholder_5) ))AND (na.grant_view >= :db_condition_placeholder_6) ; Array ( [:db_condition_placeholder_0] => 967 [:db_condition_placeholder_1] => group [:db_condition_placeholder_2] => en [:db_condition_placeholder_3] => und [:db_condition_placeholder_4] => 0 [:db_condition_placeholder_5] => all [:db_condition_placeholder_6] => 1 [:entity_type] => node ) in EntityReference_SelectionHandler_Generic->validateReferencableEntities() (line 170 of ---/sites/all/modules/entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php).
Comment #5
adshill commentedPretty sure alli.price is right that its access related. Getting the same error but with Workflow Access in place. Pretty much seems to render the module unusable for us which is a real shame! Hopefully I can get some developer hours to look into this but it won't be in the next week or two, but thought I better report the error here too!
Thanks,
Adam
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1)) AND(( (na.gid = :db_condition_placeholder_2) AND (na.realm = :db_condition_placeholder_3) )OR( (na.gid = :db_condition_placeholder_4) AND (na.realm = :db_condition_placeholder_5) )OR( (na.gid = :db_condition_placeholder_6) AND (na.realm = :db_condition_placeholder_7) ))AND (na.grant_view >= :db_condition_placeholder_8) ; Array ( [:db_condition_placeholder_0] => 22 [:db_condition_placeholder_1] => job_vacancy [:db_condition_placeholder_2] => 0 [:db_condition_placeholder_3] => all [:db_condition_placeholder_4] => 1 [:db_condition_placeholder_5] => workflow_access [:db_condition_placeholder_6] => 0 [:db_condition_placeholder_7] => workflow_access_owner [:db_condition_placeholder_8] => 1 [:entity_type] => node ) in EntityFieldQuery->execute() (line 1136 of /var/www/vhosts/XXXXXXXX/httpdocs/includes/entity.inc).Comment #6
amitaibuThere are many modules states in the issue. It would be good, if you can disable them on by one -- or better start form a fresh install, to be able to reproduce it.
Comment #7
Anonymous (not verified) commentedHi there,
like in my post here http://drupal.org/node/1325628#comment-5725380 and here http://drupal.org/node/1325628#comment-5729818 I have same problem with Entity Reference and Taxonomy Access Control. After applying this patch http://drupal.org/node/1325628#comment-5571342 problem is only with reference to user. Can anyone help?
Comment #8
Admdebian commentedI have the same bug.
If I try to save content...I have the same bug with user uid 1:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, :entity_type AS entity_type FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) AND (node.language IN (:db_condition_placeholder_3, :db_condition_placeholder_4)) AND(( (na.gid = :db_condition_placeholder_5) AND (na.realm = :db_condition_placeholder_6) )OR( (na.gid = :db_condition_placeholder_7) AND (na.realm = :db_condition_placeholder_8) )OR( (na.gid = :db_condition_placeholder_9) AND (na.realm = :db_condition_placeholder_10) )OR( (na.gid = :db_condition_placeholder_11) AND (na.realm = :db_condition_placeholder_12) ))AND (na.grant_view >= :db_condition_placeholder_13) ; Array ( [:db_condition_placeholder_0] => 42 [:db_condition_placeholder_1] => agenda_br [:db_condition_placeholder_2] => scarpa_oa [:db_condition_placeholder_3] => en [:db_condition_placeholder_4] => und [:db_condition_placeholder_5] => 0 [:db_condition_placeholder_6] => all [:db_condition_placeholder_7] => 4 [:db_condition_placeholder_8] => content_access_author [:db_condition_placeholder_9] => 2 [:db_condition_placeholder_10] => content_access_rid [:db_condition_placeholder_11] => 4 [:db_condition_placeholder_12] => content_access_rid [:db_condition_placeholder_13] => 1 [:entity_type] => node ) in EntityFieldQuery->execute() (line 1136 of /var/www/*/includes/entity.inc).
Comment #9
feadin commentedI got the same error. It only happens when trying to set or update referenced fields and using access control. It goes away if I check the "Bypass content access control" permission for that user... but I really don't want to do that :)
I checked all other permissions BTW and the only way to get rid of this error is checking the Bypass content access control permission.
Not sure if it's an Entity Reference bug or it belongs to Access Control/Content Access/ACL.
Comment #10
heatherwoz commentedI started getting this error after installing view_unpublished. It didn't happen for user 1. After disabling view_unpublished, the error went away. Don't have anything more specific to add at this point. Except that if the error is happening with so many permission-related modules, it seems like Entity Reference might be implementing something incorrectly somewhere.
Comment #11
johnpitcairn commentedAnd for me, it's with Domain access enabled.
Comment #12
Anonymous (not verified) commentedI had problem only with reference to user but when I set field to not obligatory (like it was before) everything seems to working now. Maybe it is workaround for someone until patch release.
Comment #13
feadin commentedIn my case all the affected referenced fields are not obligatory, so unfortunately this workaround won't work.
Comment #14
feadin commentedComment #15
heatherwoz commentedI've done some further reading and it turns out this issue is actually caused by a bug in core, so we can't expect a fix in this module. If you want to follow the issue and speed it's progress see #1325628: EntityFieldQuery::propertyQuery missing fully qualified column names causes ambiguous column DB error
Comment #16
DuchessOfKvetch commentedI get this error whenever I try to save or edit a new blog entry. I have a custom content type, called "Character", that I reference inside the blog schema as an additional field.
This worked all well and dandy until anyone NOT an admin tries to set the Character field for their own blog entries.
I tracked it down to occuring somewhere inside \sites\all\modules\entityreference\plugins\selectionEntityReference_SelectionHandler_Generic.class.php, in a function called validateReferencableEntities(). This calls buildEntityFieldQuery(), which flushes out the main query logic. There was a reference in the EntityFieldQuery doc (http://drupal.org/node/1343708) that said the query might need to run as a specific user with proper permissions, so I added the line:
$query->addMetaData('account', user_load(1));... right after the other "addMetaData" call on line 198.
This is no doubt a hack- perhaps even an undesirable one (force running as admin?) - but it got me past this show-stopping bug.
Comment #17
clashar commentedDuchessOfKvetch,
thank you! your solution #16 worked well for me!
Comment #18
Fred75 commentedHello DuchessOfKvetsch,
Works for me too. Thank you so much for the tip: I was beginning to feel desperate. :)
Hope forcing user 1 does not create a security risk, though.
What do you guys think about this issue?
Cheers :)
Comment #19
amitaibuSeems to be related to #1325628: EntityFieldQuery::propertyQuery missing fully qualified column names causes ambiguous column DB error
Comment #20
damien tournoud commentedThis is a Drupal Core bug (#1325628: EntityFieldQuery::propertyQuery missing fully qualified column names causes ambiguous column DB error). Nothing we can do about it in Entity Reference.
Comment #21
vali hutchison commentedFor reference: I had this issue when I had og_access module enabled (part of organic groups), and was ok once disabled. I also had view_unpublished enabled but with og_access disabled entity reference worked fine.
BUT: I was running on Drupal 7.12 - and when I upgraded to Drupal 7.14 then the problem disappeared with og_access enabled.
So would recommend upgrading to Drupal 7.14
Comment #21.0
vali hutchison commentedupdated issue, error is being quirky!