{"id":7005,"date":"2014-05-16T08:58:32","date_gmt":"2014-05-16T08:58:32","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/column-not-found-nid-in-on-clause-using-i18n-entityreference-field_sql_storage-collection-of-common-programming-errors\/"},"modified":"2014-05-16T08:58:32","modified_gmt":"2014-05-16T08:58:32","slug":"column-not-found-nid-in-on-clause-using-i18n-entityreference-field_sql_storage-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/column-not-found-nid-in-on-clause-using-i18n-entityreference-field_sql_storage-collection-of-common-programming-errors\/","title":{"rendered":"Column not found (nid) in on clause, using i18n, entityreference, field_sql_storage-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m using Drupal 7.14 and Entity API and Reference 1.0-rc3. I get this error when saving a node that has some custom fields using references.<\/p>\n<blockquote>\n<p>PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column &#8216;field_data_body0.nid&#8217; in &#8216;on clause&#8217;: SELECT field_data_body0.entity_type AS entity_type, field_data_body0.entity_id AS entity_id, field_data_body0.revision_id AS revision_id, field_data_body0.bundle AS bundle FROM {field_data_body} field_data_body0 INNER JOIN {node} node ON field_data_body0.nid = node.nid WHERE (field_data_body0.deleted = :db_condition_placeholder_0) AND (field_data_body0.entity_type = :db_condition_placeholder_1) AND (field_data_body0.bundle IN (:db_condition_placeholder_2, :db_condition_placeholder_3)) AND (field_data_body0.entity_id IN (:db_condition_placeholder_4)) AND (node.language IN (:db_condition_placeholder_5, :db_condition_placeholder_6)) ORDER BY field_data_body0.body_value ASC; Array ( [:db_condition_placeholder_0] =&gt; 0 [:db_condition_placeholder_1] =&gt; node [:db_condition_placeholder_2] =&gt; news [:db_condition_placeholder_3] =&gt; page [:db_condition_placeholder_4] =&gt; 25 [:db_condition_placeholder_5] =&gt; it [:db_condition_placeholder_6] =&gt; und ) in field_sql_storage_field_storage_query() (linea 577 di \/home\/morpheu5\/web\/xdatanet\/modules\/field\/modules\/field_sql_storage\/field_sql_storage.module).<\/p>\n<\/blockquote>\n<p>What bothers me is that, first of all there&#8217;s a zero appended to the name of the table, and second, if I add that nid column to that table, Drupal is happy and everything seems to work.<\/p>\n<p>I suspect there must have been some update gone horribly wrong, since maintenance is not under my control, and I had to implement some new features working on my local copy which at that time was already completely out of sync with the client&#8217;s staging and production servers.<\/p>\n<p>I tried a number of patches, and I&#8217;ve gone through the code myself but I&#8217;m not <strong>this<\/strong> familiar with Drupal.<\/p>\n<p><strong>EDIT<\/strong><\/p>\n<p>It seems the nid column is getting added at some point in <code>function preExecute<\/code> in <code>includes\/database\/select.inc<\/code> specifically at row 1236<\/p>\n<pre><code>drupal_alter($hooks, $query);\n<\/code><\/pre>\n<p>the hooks acting here are<\/p>\n<ul>\n<li><code>query<\/code><\/li>\n<li><code>query_entity_field_access<\/code><\/li>\n<li><code>query_node_access<\/code><\/li>\n<li><code>query_entityreference<\/code><\/li>\n<\/ul>\n<p>but after a hour long investigation I only came up with a huge headache, and I&#8217;m still not sure if I actually found and debugged all of those hooks. As far as I could see, the <code>nid<\/code> column is not present before the drupal_alter call while it is after, but it&#8217;s there at the beginning of each hook_query_TAG_alter I was able to find.<\/p>\n<p>I must be missing something.<\/p>\n<p><strong>EDIT 2<\/strong><\/p>\n<p>The culprit seems to be <code>i18n<\/code>, specifically <code>i18n_select<\/code>, more specifically at row 137 of <code>i18n_select.module<\/code> where it adds the <code>nid<\/code> column.<\/p>\n<p><strong>EDIT 3<\/strong><\/p>\n<p>There, I opened a bug: https:\/\/drupal.org\/node\/1679646<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using Drupal 7.14 and Entity API and Reference 1.0-rc3. I get this error when saving a node that has some custom fields using references. PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column &#8216;field_data_body0.nid&#8217; in &#8216;on clause&#8217;: SELECT field_data_body0.entity_type AS entity_type, field_data_body0.entity_id AS entity_id, field_data_body0.revision_id AS revision_id, field_data_body0.bundle AS bundle FROM {field_data_body} field_data_body0 INNER JOIN [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7005","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7005"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7005\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}