I'm working on this as part of the external tables integration. The problem was that I got an SQL error in views of external tables that were using manual relationships. If you looked at the SQL generated, you would see a " .vid" in the join instead of "ext_node.vid", like the table name went missing. I ended up tracking it down to the relationship handler. It was assigning the table alias to the left table, instead of the actual table name.
- $def['left_table'] = $this->table_alias;
+ $def['left_table'] = $this->table;
Because it had an alias, not the actual table name, the get_table_info call in the views_query class failed, leaving $left empty, so that only " .$this->left_field" was output to the query.
$left = $query->get_table_info($this->left_table);
$left_field = "$left[alias].$this->left_field";
After the change, the query works correctly. Note: I've only tested this change for external tables, but I would think it would effect any internal table that happened to have an alias different then the actual table name.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views3_relationship_should_use_table_not_alias.patch | 836 bytes | frankcarey |
Comments
Comment #1
frankcarey commentedOn second thought, this may be introduced by me... i'll get back to you about this
Comment #2
frankcarey commentedNope, issue is legit. One clear example is that join (automatic) relationships use the actual table name, and not a table alias and works as expected. This only effects relationship (manual) relationships.
fixing version number too.
Comment #3
frankcarey commentedRelated external tables issue #576694: Enable views to handle external tables properly, allowing for joins across tables in different mysql databases needs this patch to work.
Comment #4
dagmarThere is no patch. Nothing to review, sorry.
Comment #5
frankcarey commentedoops, this *should* be it!
Comment #6
frankcarey commentedany updates on this bug?
Comment #7
merlinofchaos commentedAs I just mentioned in http://drupal.org/node/576694#comment-2743632 I think this code is needed to chain relationships properly.
Comment #8
frankcarey commented"Because it had an alias, not the actual table name, the get_table_info call in the views_query class failed, leaving $left empty, so that only " .$this->left_field" was output to the query." Any ideas about this?
Comment #9
merlinofchaos commentedI haven't actually *seen* this bug so I'm not sure how to reproduce it.
Comment #10
merlinofchaos commentedThe code is supposed to be able to account for the situation where the left join is an alias, because that's what query::adjust_join() does. Maybe the whole problem is that $join->adjusted = TRUE is not set?
Comment #11
merlinofchaos commentedI'm still pretty sure this fix will break chained relationships. Without being able to reproduce the bug this is fixing, I'm not willing to touch this.
Comment #12
esmerel commentedNo updates for more than 30 days.