Преглед изворни кода

Fix to chado join handler that add's alias' to each table added to satisfy foreign key constraint. This takes into account the edge case where there are two foreign key calls to the same table.

Lacey Sanderson пре 12 година
родитељ
комит
867229ac5d
1 измењених фајлова са 8 додато и 7 уклоњено
  1. 8 7
      tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

+ 8 - 7
tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

@@ -152,14 +152,15 @@ class views_handler_join_chado_aggregator extends views_join {
       foreach ($table_desc['foreign keys'] as $defn) {
         if ($defn['table'] != $opt['left_table']) {
           foreach ( $defn['columns'] as $left => $right) {
+            $table_alias = 'fk_' . $defn['table']  . '_' . $left;
             $left = $opt['table'] . '.' . $left;
-            $right = $defn['table'] . '.' . $right;
-            $joins[] = "LEFT JOIN $defn[table] $defn[table] ON $left=$right";
-          }
+            $right = $table_alias . '.' . $right;
+            $joins[] = "LEFT JOIN $defn[table] $table_alias ON $left=$right";
 
-          // Fields to be selected from joined table
-          $join_table = tripal_core_get_chado_table_schema($defn['table']);
-          $select_fields[ $defn['table'] ] = $join_table['fields'];
+            // Fields to be selected from joined table
+            $join_table = tripal_core_get_chado_table_schema($defn['table']);
+            $select_fields[ $table_alias ] = $join_table['fields'];
+          }
         }
       }
 
@@ -233,7 +234,7 @@ class views_handler_join_chado_aggregator extends views_join {
       foreach ($opt['additional_joins'] as $join_defn) {
 
         // Add the join SQL in
-        $table = ($join_defn['table_alias']) ? $join_defn['table_alias'] : $join_defn['table'];
+        $table = ($join_defn['table_alias']) ? $join_defn['table_alias'] : 'adt_' . $join_defn['table'] . '_' . $join_defn['left_field'];
         $left = $join_defn['left_table'] . '.' . $join_defn['left_field'];
         $right = $table . '.' . $join_defn['field'];
         $joins[] = "LEFT JOIN $join_defn[table] $table ON $left=$right";