{"id":1052,"date":"2022-08-30T15:11:35","date_gmt":"2022-08-30T15:11:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/unknown-column-errors-because-of-table-alias-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:11:35","modified_gmt":"2022-08-30T15:11:35","slug":"unknown-column-errors-because-of-table-alias-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/unknown-column-errors-because-of-table-alias-collection-of-common-programming-errors\/","title":{"rendered":"Unknown column errors because of table alias-Collection of common programming errors"},"content":{"rendered":"<p>Because of truncated identifiers with more than 63 chars, causing Views to break<\/p>\n<p>It causes errors like<\/p>\n<blockquote>\n<p>SQLSTATE[42S22]: Column not found: 1054 Unknown column &#8216;taxonomy_term_data_node__draggableviews_structure_weight_coalesce&#8217; in &#8216;order clause&#8217;<\/p>\n<\/blockquote>\n<p><strong>Goal:<\/strong> I want to change the table alias from <code>_draggableviews_structure_<\/code> to <code>_dv_<\/code><\/p>\n<p>If I change<\/p>\n<pre><code>    $data['draggableviews_structure']['weight'] = array(\n      'title' =&gt; t('Weight'),\n      'group' =&gt; t('Draggableviews'),\n      'field' =&gt; array(\n        'help' =&gt; t('Display the weight value.'),\n        'handler' =&gt; 'views_handler_field_numeric',\n        'click sortable' =&gt; TRUE,\n      ),\n      'sort' =&gt; array(\n        'help' =&gt; t('Sort entities by the draggableviews weight table field.'),\n        'handler' =&gt; 'draggableviews_handler_sort',\n      ),\n    );\n\n    $data['draggableviews_structure']['parent'] = array(\n      'title' =&gt; t('Parent'),\n      'help' =&gt; t('The parent entity id.'),\n      'group' =&gt; t('Draggableviews'),\n      'field' =&gt; array(\n        'handler' =&gt; 'views_handler_field_numeric',\n      ),\n    );\n\n  \/\/ Explain to every entity how to join with draggableviews structure table.\n    $data['draggableviews_structure']['table']['join'][$info['base table']] = array(\n      'handler' =&gt; 'draggableviews_join_handler',\n      'left_table' =&gt; $info['base table'], \/\/ Because this is a direct link it could be left out.\n      'left_field' =&gt; $info['entity keys']['id'],\n      'field' =&gt; 'entity_id',\n    );\n<\/code><\/pre>\n<p>to<\/p>\n<pre><code>   $data['dv']['weight'] = array(\n     'title' =&gt; t('Weight'),\n     'group' =&gt; t('Draggableviews'),\n     'field' =&gt; array(\n       'help' =&gt; t('Display the weight value.'),\n       'handler' =&gt; 'views_handler_field_numeric',\n       'click sortable' =&gt; TRUE,\n     ),\n     'sort' =&gt; array(\n       'help' =&gt; t('Sort entities by the draggableviews weight table field.'),\n       'handler' =&gt; 'draggableviews_handler_sort',\n     ),\n   );\n\n   $data['dv']['parent'] = array(\n     'title' =&gt; t('Parent'),\n     'help' =&gt; t('The parent entity id.'),\n     'group' =&gt; t('Draggableviews'),\n     'field' =&gt; array(\n       'handler' =&gt; 'views_handler_field_numeric',\n     ),\n   );\n\n   \/\/ Explain to every entity how to join with draggableviews structure table.\n   $data['dv']['table']['join'][$info['base table']] = array(\n     'handler' =&gt; 'draggableviews_join_handler',\n     'table' =&gt; 'draggableviews_structure',\n     'left_table' =&gt; $info['base table'], \/\/ Because this is a direct link it could be left out.\n     'left_field' =&gt; $info['entity keys']['id'],\n     'field' =&gt; 'entity_id',\n   );\n<\/code><\/pre>\n<p>This works. However, all of the views with draggableviews fields\/sort components have disappeared. In the admin view, views complains able missing relationship, and it trying to fix them for you. If you read the fields, the view works again.<\/p>\n<p>Is there a way to fix this, without manually changing everything? Is there a better way to solve it?<\/p>\n<ol>\n<li>\n<p>I&#8217;ve used the MD5 alias patch from that issue queue here: http:\/\/drupal.org\/files\/issues\/views-571548_40.patch (#40) to fix that issue.<\/p>\n<p>You may need to apply the patch manually to views\/includes\/query.inc<\/p>\n<p>The good news is, if you can do that, it should fix all those alias truncation issues for you.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:19:38. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Because of truncated identifiers with more than 63 chars, causing Views to break It causes errors like SQLSTATE[42S22]: Column not found: 1054 Unknown column &#8216;taxonomy_term_data_node__draggableviews_structure_weight_coalesce&#8217; in &#8216;order clause&#8217; Goal: I want to change the table alias from _draggableviews_structure_ to _dv_ If I change $data[&#8216;draggableviews_structure&#8217;][&#8216;weight&#8217;] = array( &#8216;title&#8217; =&gt; t(&#8216;Weight&#8217;), &#8216;group&#8217; =&gt; t(&#8216;Draggableviews&#8217;), &#8216;field&#8217; =&gt; array( [&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-1052","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1052","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=1052"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}