I've been trying to get a comment entity reference field set up in a node, but every time I try the following things happen:
1. I go to my content type's 'Manage fields' area.
2. I create a new entity reference field.
3. On the next screen, I select Comments for the target type and then select the comment bundles below. I leave the Mode as Simple.
4. When I click Save field settings, I get 2 conflicting messages. The first says the fields has been updated (highlighted in green). The second message is a PDOException:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'comment.node_type' in 'where clause': SELECT comment.cid AS entity_id, :entity_type AS entity_type, NULL AS revision_id FROM {comment} comment INNER JOIN {node} n ON n.nid = comment.nid WHERE (comment.node_type IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => comment_node_article [:entity_type] => comment ) in EntityFieldQuery->execute() (line 1145 of /var/www/d7/includes/entity.inc).
Based on this error, I'm not sure if the problem lies with Entity Reference or Core. I've tried this on a fresh install, with only Entity Reference and its dependencies enabled with the same results. Any ideas? Thanks.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | entityreference-queryalter-1892742-6.patch | 939 bytes | sprocketman |
| #6 | entityreference-queryalter-1892742-5.patch | 939 bytes | sprocketman |
| #4 | entityreference-queryalter-1892742-3.patch | 931 bytes | sprocketman |
| #2 | entityreference-queryalter-1892742-2.patch | 931 bytes | sprocketman |
Comments
Comment #1
sprocketman commentedI've tried this again with another fresh install of D7 and now I'm having no problems. So, closing this issue.
Comment #2
sprocketman commentedUgh...sorry to reopen, but I was mistaken in my previous comment. The bug still remains. Basically, the module is trying to override a faulty query generated by core (I believe) in EntityReference_SelectionHandler_Generic.class.php related to the fact that the comment module sets the entity key "bundle" to "node_type" in comment_entity_info(). When entityreference tries to build a list of entity bundles for the comment type, the initial query attempts to look for a field (node_type) in the comment table that doesn't exist. In your alteration, you were looking for $condition['field'] = 'node_type' (line 453), but instead it should look for $condition['field'] = 'comment.node_type'. A patch is included here.
Comment #4
sprocketman commentedSorry, I think I needed to change the version to the -dev.
Comment #6
sprocketman commentedWhoops, think I need to remove --no-prefix from my git diff statement. Sorry, a little new to this.
Comment #7
sprocketman commentedComment #8
czigor commentedWorks great for me, thanks!
Comment #9
willowdigit commentedWorks for me as well, thank you.
Whys has this not been committed? Is it because it is a fix for a faulty query in core as suggested by @sprocketman#2?
Comment #10
franzThis looks good, fixed error. I think it should get committed.
Comment #11
polSame problem here when trying to run: drush ter-rebuild from Taxonomy Entity Index.
The patch doesn't seems to fix the problem either.
Comment #12
jami commentedThe patch in #7 fixed the error. Thanks!
Comment #13
MorinLuc0 commentedTested on the 7.x-1.x-dev version with drupal core 7.50 and error still exist but can't be validated till test are provided.
Comment #14
tky commentedI got a similar PDOException error too.
But the message did not appear when I add a comment reference field as sprocketman did in the first place. The error message shows every time in the log while I get into a node create form via entityreference prepopulate link. What I got in front end is always an "Site encountered an Unexpected Error" message.
If the target entity is replaced from Comment to Content, the reference filed works fine and gets no any error message.
My Drupal is 7.53, has entityreference 7.x-1.x-dev (2017-Apr-13) and entityreference_prepopulate 7.x-1.7 installed
Comment #15
mennovdheuvel commentedGetting this same error now:
This happens after trying to reopen comments on a node after it had been closed before, and another node holds a reference to a comment on the node. Core 7.59 and entityreference 7.x-1.5.
Is there any easy workaround?
Comment #16
mennovdheuvel commentedRight. I got around this error using the following patch for EntityReference_SelectionHandler_Generic.class.php:
Line 465 was:
and I changed this to:
I'm not sure if the field ever is just "node_type" without the table name and, if so, where the variations come from. That's for someone else to figure out.
Comment #17
tky commented#16 work for me.
Thanks a lot.
Comment #18
delacosta456 commentedhi #7 worked for me too
Thanks
Comment #19
mimalef70 commentedHi, Whys has this not been committed ?
Thanks
Comment #20
delacosta456 commentedhi @mimalef70
May be because patch has not gotten enough test by community.