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.

Comments

frankcarey’s picture

Status: Needs review » Needs work

On second thought, this may be introduced by me... i'll get back to you about this

frankcarey’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs work » Needs review

Nope, 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.

frankcarey’s picture

dagmar’s picture

Status: Needs review » Active

There is no patch. Nothing to review, sorry.

frankcarey’s picture

Status: Active » Needs review
StatusFileSize
new836 bytes

oops, this *should* be it!

frankcarey’s picture

any updates on this bug?

merlinofchaos’s picture

As I just mentioned in http://drupal.org/node/576694#comment-2743632 I think this code is needed to chain relationships properly.

frankcarey’s picture

"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?

merlinofchaos’s picture

I haven't actually *seen* this bug so I'm not sure how to reproduce it.

merlinofchaos’s picture

The 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?

merlinofchaos’s picture

Status: Needs review » Postponed (maintainer needs more info)

I'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.

esmerel’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

No updates for more than 30 days.