Browse Source

Tripal Views: fixed relationships and joins

Lacey Sanderson 11 years ago
parent
commit
f74ce062df

+ 22 - 117
tripal_views/api/tripal_views.api.inc

@@ -339,12 +339,9 @@ function tripal_views_integration_add_entry($defn_array) {
             'left_field' => $join['field'],
           );
 
-          if (!empty($join['handler'])) {
-            $join_record['handler'] = $join['handler'];
-          }
-          else {
-            $join_record['handler'] = 'views_join';
-          }
+          $join_record['handler'] = (!empty($join['handler'])) ? $join['handler'] : 'views_join';
+          $join_record['relationship_handler'] = (!empty($join['relationship_handler'])) ? $join['relationship_handler'] : 'views_handler_relationship';
+          $join_record['relationship_only'] = (!empty($join['relationship_only'])) ? $join['relationship_only'] : 0;
 
           if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
             $status = drupal_write_record('tripal_views_join', $join_record);
@@ -674,7 +671,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
     }
   }
 
-  // Add Joins & Relationship Handlers to fields
+  // Add Joins & Relationships for foreign keys to fields
   if (!isset($schema['foreign keys'])) {
     $schema['foreign keys'] = array();
     watchdog('tripal_views', 'There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_WARNING);
@@ -686,123 +683,31 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
         'table' => $foreign_key_schema['table'],
         'field' => $right_field,
         /**D6 'handler' => 'views_handler_join_chado_aggregator'*/
-        'handler' => 'views_handler_join'
-      );
-
-      // Relationship Handler
-      $defn_array['fields'][$left_field]['handlers']['relationship'] = array(
-        /**D6 'name' => 'chado_views_handler_relationship',*/
-        'name' => 'views_handler_relationship',
-        'base' => $foreign_key_schema['table'],
-        'base field' => $right_field,
-        'label' => $table_name . ' ' . $left_field . ' => ' . $foreign_key_schema['table'] . ' ' . $right_field
+        'handler' => 'views_handler_join',
+        'relationship_handler' => 'views_handler_relationship',
       );
     }
   }
 
-  return $defn_array;
-}
+  // Add in reverse relationships
+  if (isset($schema['referring_tables'])) {
+    foreach ($schema['referring_tables'] as $referring_table) {
 
-/**
- * Adds the joins necessary to link a chado table to it's node counterpart
- *
- * @param $defn_array
- *   The current definition array for a given table
- *
- * @ingroup tripal_views_api
- */
-function tripal_views_add_node_relationship_to_chado_table_integration($defn_array) {
-  $integrations[$defn_array['table']] = $defn_array;
-  $primary_key = $defn_array['table'] . '_id';
-  $chado_linking = 'chado_' . $defn_array['table'];
-
-  if (empty($defn_array['table'])) {
-    watchdog('tripal_views','Tried to add a node=>chado relationship for an empty table defn: %defn',
-      array('%defn' => print_r($defn_array,TRUE)),WATCHDOG_WARNING);
-    return FALSE;
+      // D7 @todo: fix referring_tables in schema to list the keys like foreign keys does
+      $referring_schema = tripal_core_get_chado_table_schema($referring_table);
+      $referring_schema_fk_columns = $referring_schema['foreign keys'][$table_name]['columns'];
+      foreach ($referring_schema_fk_columns as $left_field => $right_field) {
+        $defn_array['fields'][$right_field]['joins'][ $referring_table ] = array(
+          'table' => $referring_table,
+          'field' => $left_field,
+          'relationship_handler' => 'views_handler_relationship',
+          'relationship_only' => 1
+        );
+      }
+    }
   }
 
-  // Add table.primary_key => chado_table.primary key join to $defn_array
-  $integrations[$defn_array['table']]['fields'][$primary_key]['joins'][$chado_linking] = array(
-    'table' => $chado_linking,
-    'field' => $primary_key,
-  );
-
-  // Create chado_table defn_array
-  $integrations[$chado_linking] = array(
-    'table' => $chado_linking,
-    'type' => 'drupal',
-    'name' => 'Chado ' . $defn_array['table'] . ' Node',
-    'description' => 'Links chado content to its drupal node counterpart',
-    'priority' => $defn_array['priority'],
-    'base_table' => FALSE,
-    'fields' => array(
-      $primary_key => array(
-        'name' => $primary_key,
-        'title' => ucwords(str_replace('_', ' ', $primary_key)),
-        'type' => 'int',
-        'description' => 'The primary key of the chado ' . $defn_array['table'] . ' table',
-        'handlers' => array(),
-        'joins' => array(
-          $defn_array['table'] => array(
-            'table' => $defn_array['table'],
-            'field' => $primary_key,
-          )
-        ),
-      ),
-      'nid' => array(
-        'name' => 'nid',
-        'title' => 'Node ID',
-        'type' => 'int',
-        'description' => 'Link ' . ucfirst($defn_array['table']) . ' to it\'s node',
-        'handlers' => array(
-          'relationship' => array(
-            'name' => 'chado_views_handler_relationship_to_node',
-            'title' => ucfirst($defn_array['table']) . ' to Node',
-            'label' => ucfirst($defn_array['table']) . ' to Node',
-            'base table' => $defn_array['table'],
-            'base field' => $primary_key
-          )
-        ),
-        'joins' => array(
-          'node' => array(
-            'table' => 'node',
-            'field' => 'nid',
-          ),
-        ),
-      )
-    ),
-  );
-
-  // Create node defn_array
-  $integrations['node'] = array(
-    'table' => 'node',
-    'name' => 'Node',
-    'description' => 'Primary Drupal Content',
-    'priority' => $defn_array['priority'],
-    'additional_content' => TRUE, // Allows multiple modules to add to the node setup
-    'fields' => array(
-      'nid' => array(
-        'name' => 'nid',
-        'title' => 'Node ID',
-        'type' => 'int',
-        'description' => 'the primary key of the drupal node table',
-        'handlers' => array(),
-        'joins' => array(
-          $defn_array['table'] => array(
-            'table' => $defn_array['table'],
-            'field' => 'nid',
-          ),
-          $chado_linking => array(
-            'table' => $chado_linking,
-            'field' => 'nid',
-          ),
-        ),
-      ),
-    ),
-  );
-
-  return $integrations;
+  return $defn_array;
 }
 
 /**

+ 44 - 0
tripal_views/tripal_views.install

@@ -107,6 +107,39 @@ function tripal_views_update_6040() {
   return t('Updated Tripal Views to handle multiple Integrations and keep track of fields.');
 }
 
+/**
+ * Tripal Views Update for 7.x-2.0
+ *   - Add relationship_only field to tripal_views_join
+ *   - Add relationship_handler field to tripal_views_join
+ */
+function tripal_views_update_7020() {
+
+  // Add relationship_handler to tripal_views_join
+  db_add_field(
+    'tripal_views_join',
+    'relationship_handler',
+    array(
+      'type' => 'varchar',
+      'length' => '255',
+      'not null' => TRUE,
+      'default' => 'views_handler_relationship'
+    )
+  );
+
+  // Add relationship_only to tripal_views_join
+  db_add_field(
+    'tripal_views_join',
+    'relationship_only',
+    array(
+      'type' => 'int',
+      'not null ' => TRUE,
+      'default' => 0
+    )
+  );
+
+  return t('Updated Tripal Views to better handle relationships. Relationships are now handled through joins rather than handlers (backwards compatible).');
+}
+
 /**
  * Describe the Tripal Views Schema
  *
@@ -264,6 +297,17 @@ function tripal_views_views_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
+      'relationship_handler' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => 'views_handler_relationship'
+      ),
+      'relationship_only' => array(
+        'type' => 'int',
+        'not null ' => TRUE,
+        'default' => 0
+      ),
       'arguments' => array(
         'description' => 'arguments that may get passed to the handler',
         'type' => 'text',

+ 116 - 238
tripal_views/tripal_views.views.inc

@@ -1,7 +1,5 @@
 <?php
 
-// include('views/handlers/views_handler_join_chado_through_linking.inc');
-// include('views/handlers/views_handler_join_chado_aggregator.inc');
 include('api/tripal_views.api.inc');
 
 
@@ -67,6 +65,9 @@ function tripal_views_views_handlers() {
     'handlers' => array(
 
       // Custom Tripal Filter Handlers
+      'tripal_views_handler_filter_no_results' => array(
+        'parent' => 'views_handler_filter'
+      ),
       /** D7 @todo: get handlers working
       'tripal_views_handler_filter_file_upload' => array(
         'parent' => 'views_handler_filter',
@@ -74,9 +75,6 @@ function tripal_views_views_handlers() {
       'tripal_views_handler_filter_textarea' => array(
         'parent' => 'views_handler_filter',
       ),
-      'tripal_views_handler_filter_no_results' => array(
-        'parent' => 'views_handler_filter'
-      ),
       'tripal_views_handler_filter_select_cvterm' => array(
         'parent' => 'views_handler_filter_string',
       ),
@@ -199,6 +197,7 @@ function tripal_views_views_handlers() {
  * @todo add if !<chado/drupal same db> around NID portion
  *
  * @ingroup tripal_views
+ */
 function tripal_views_views_pre_render(&$view) {
 
   // We need to unset the exposed_input for the view so we can repopulate that
@@ -211,10 +210,9 @@ function tripal_views_views_pre_render(&$view) {
   // results in other formats (e.g. Excel, FASTA, CSV, etc.).  The Views Data
   // Export module provides small images at the bottom, but we want to provide
   // a more intutitive interface for getting different file formats
-  $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
-  $view->attachment_after = $form;
+  // $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
+  // $view->attachment_after = $form;
 }
-*/
 
 /**
  * Generates a dynamic data array for Views
@@ -231,10 +229,10 @@ function tripal_views_views_pre_render(&$view) {
 function tripal_views_views_data() {
   $data = array();
 
-  // Make sure all chado tables are integrated
+  // MAKE SURE ALL CHADO TABLES ARE INTEGRATED
   tripal_views_integrate_all_chado_tables();
 
-  // Define Global Fields
+  // DEFINE GLOBAL FIELDS
   // Filter handler that lets the admin say:
   // "Show no results until they enter search parameters"
   $data['views']['search_results'] = array(
@@ -247,7 +245,7 @@ function tripal_views_views_data() {
 
   $tvi_query = db_query('SELECT * FROM {tripal_views}');
 
-  // D7 TODO: Check DBTNG changes work
+  // INTEGRATE THE LIGHTEST SETUP FOR EACH TABLE
   foreach ($tvi_query as $tvi_row) {
 
     // check to see if this is the lightest (drupal-style) priority setup for this table
@@ -268,8 +266,9 @@ function tripal_views_views_data() {
     // indicated whether the current table is a base table or not
     $is_base_table = $tvi_row->base_table;
 
-    // populate the base table name and fields.  If an $mview_id is given
-    // then get the materialized view info, otherwise get the Chado table info
+    // POPULATE THE BASE TABLE NAME AND FIELDS
+    // If an $mview_id is given then get the materialized view info,
+    // otherwise get the Chado table info
     if ($mview_id) {
 
       // get the base table name from the materialized view
@@ -306,55 +305,6 @@ function tripal_views_views_data() {
     else {
       $base_table = $tvi_row->table_name;
 
-      // Check if we are trying to integrate the node table
-      // if we are we want to add to a current integration
-      // as compared to create a whole new one
-      if ($base_table == 'node') {
-
-      	/* -- SPF Jun 13, 2013 -- not sure why the node table
-      	 *    is included in the Chado integrated tables. I've commented
-      	 *    out.  I think it was here for integration of chado tables wiht
-      	 *    nodes, but code to do this has been added below and it's not
-      	 *    necessary to have the node table in the list of integrated tables
-      	 *
-        // Add any joins between the node table and other tables
-        // D7 TODO: Check DBTNG changes work
-        $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-        $joins = db_query($sql, $setup_id);
-        foreach ($joins as $join) {
-          $left_table = $join->left_table;
-          $left_field = $join->left_field;
-          $base_field = $join->base_field;
-          $handler = $join->handler;
-
-          // add join entry
-          $data[$base_table]['table']['join'][$left_table] = array(
-            'left_field' => $left_field,
-            'field' => $base_field,
-          );
-          if ($handler) {
-            $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
-          }
-        }
-
-
-        // Add in any handlers for node fields
-        // D7 TODO: Check DBTNG changes work
-        $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d";
-        $query = db_query($sql, $setup_id);
-        foreach ($query as $handler) {
-          $data[$base_table][$handler->column_name][$handler->handler_type]['handler'] = $handler->handler_name;
-
-          // Add in any additional arguments
-          // This should be a serialized array including (at a minimum) name => <handler name>
-          if ($handler->arguments) {
-            $data[$base_table][$handler->column_name][$handler->handler_type] = array_merge($data[$base_table][$handler->column_name][$handler->handler_type], unserialize($handler->arguments));
-          }
-        }
-        */
-        continue;
-      }
-
       // get the table description
       $table_desc = tripal_core_get_chado_table_schema($base_table);
 
@@ -378,7 +328,7 @@ function tripal_views_views_data() {
       }
     }
 
-    // Setup the base table info in the data array
+    // SETUP THE BASE TABLE INFO IN THE DATA ARRAY
     $data[$base_table]['table']['group'] = t("$tvi_row->name");
 
     if ($is_base_table) {
@@ -398,7 +348,7 @@ function tripal_views_views_data() {
       );
     }
 
-    // first add the fields
+    // ADD THE FIELDS TO THE DATA ARRAY
     foreach ($base_fields as $column_name => $base_field) {
       $data[$base_table][$column_name] = array(
         'title' => t($base_field['name']),
@@ -410,7 +360,6 @@ function tripal_views_views_data() {
 
 
       // now add the handlers
-      // D7 TODO: Check DBTNG changes work
       $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = :setup AND column_name = :column";
       $handlers = db_query($sql, array(':setup' => $setup_id, ':column' => $column_name));
       foreach ($handlers as $handler) {
@@ -422,125 +371,15 @@ function tripal_views_views_data() {
           $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
         }
       };
-
-      // add in joins to the node tables if the Chado schema is local
-		  if (tripal_core_chado_schema_exists()) {
-
-		    $linker_table = 'chado_' . $base_table;
-		    $linker_name = ucwords(str_replace('_', ' ', $base_table));
-		    $schema = tripal_core_get_chado_table_schema($base_table);
-		    $pkey = $schema['primary key'][0];
-
-		    // if a node linking table exists then add in the joins
-		    if (db_table_exists($linker_table)) {
-
-		    	// add the linker table to the data array
-			    $data[$linker_table] = array(
-			      // describe the table
-			      'table' => array(
-			        'title' => 'Chado ' . $linker_name,
-              'group' => 'Chado ' . $linker_name,
-			        // join to the base table and the node table
-			        'join' => array(
-				        $base_table => array(
-			            'left_field' => $pkey,
-			            'field' => $pkey,
-				        ),
-				        'node' => array(
-                  'left_field' => 'nid',
-                  'field' => 'nid',
-				        ),
-				      ),
-				    ),
-				    // add the nid field
-            'nid' => array(
-              'title' => t($linker_name . ' Node ID'),
-              'help' => t("The node ID for this $linker_name"),
-              'field' => array(
-                'handler' => 'views_handler_field_numeric',
-                'click sortable' => TRUE,
-              ),
-              'filter' => array(
-                'handler' => 'views_handler_filter_numeric',
-              ),
-              'sort' => array(
-                'handler' => 'views_handler_sort',
-              ),
-            ),
-            // add the primary key field
-            $pkey => array(
-              'title' => t($linker_name . ' ' . $pkey),
-              'help' => t("The $base_table primary key"),
-              'field' => array(
-                'handler' => 'views_handler_field_numeric',
-                'click sortable' => TRUE,
-              ),
-              'filter' => array(
-                'handler' => 'views_handler_filter_numeric',
-              ),
-              'sort' => array(
-                'handler' => 'views_handler_sort',
-              ),
-            ),
-          );
-
-          // add the join instructions for the base table
-          // (we'll add the recipricol joins for the node table in the hook_views_data_alter
-          /**
-          $data[$base_table]['table']['join'][$linker_table] = array(
-            'left_field' => 'organism_id',
-            'field' => 'organism_id',
-          );
-          $data[$base_table]['table']['join']['node'] = array(
-            'left_table' => $linker_table,
-            'left_field' => 'organism_id',
-            'field' => 'organism_id',
-          );
-          */
-
-
-			    // Add relationship between linker and base table
-			    $data[$linker_table][$base_table . '_nid'] = array(
-			      'group' => $linker_name,
-			      'title' => $linker_name . 'Node',
-			      'help' => "Links Chado $linker_name Fields/Data to the Nodes in the current View.",
-			      'real field' => $pkey,
-			      'relationship' => array(
-			        'handler' => 'views_handler_relationship',
-			        'title' => t("Chado => $linker_name"),
-			        'label' => t("Chado => $linker_name"),
-			        'real field' => $pkey,
-			        'base' => $base_table,
-			        'base field' => $pkey
-			      ),
-			    );
-
-			    // Add node relationship to base table
-			    $data[$linker_table][$linker_table .'_nid'] = array(
-			      'group' => $linker_name,
-			      'title' => $linker_name . 'Node',
-			      'help' => "Links Chado $linker_name Fields/Data to the Nodes in the current View.",
-			      'real field' => 'nid',
-			      'relationship' => array(
-			        'handler' => 'views_handler_relationship',
-			        'title' => t('Chado => Node'),
-			        'label' => t('Chado => Node'),
-			        'real field' => 'nid',
-			        'base' => 'node',
-			        'base field' => 'nid'
-			      ),
-			    );
-		    }
-		  }
     }
 
+    // ADD JOINS & RELATIONSHIPS TO DATA ARRAY
     // only add joins if this is a base table
     // this keeps the list of available fields manageable
     // all other tables should be added via relationships
-    // D7 todo: add tripal_views_join field that determines whether a join is added
+    // D7 @todo: add tripal_views_join field that determines whether a join is added
     if ($is_base_table) {
-      // now add the joins
-      // D7 TODO: Check DBTNG changes work
+
       $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
       $joins = db_query($sql, array(':setup' => $setup_id));
       if (!isset($joins)) {
@@ -549,8 +388,11 @@ function tripal_views_views_data() {
       foreach ($joins as $join) {
         $left_table = $join->left_table;
         $left_field = $join->left_field;
+        $base_table = $join->base_table;
         $base_field = $join->base_field;
         $handler = $join->handler;
+        $base_title = ucwords(str_replace('_', ' ', $base_table));
+        $left_title = ucwords(str_replace('_', ' ', $left_table));
 
         // if the 'node' table is in our integrated list then
         // we want to skip it. It shouldn't be there.
@@ -559,81 +401,143 @@ function tripal_views_views_data() {
         }
 
         // add join entry
-        $data[$left_table]['table']['join'][$base_table] = array(
-          'left_field' => $base_field,
-          'field' => $left_table . '_id',
+        if (!$join->relationship_only) {
+          $data[$left_table]['table']['join'][$base_table] = array(
+            'left_field' => $base_field,
+            'field' => $left_table . '_id',
+          );
+          if ($handler) {
+            $data[$left_table]['table']['join'][$base_table]['handler'] = $handler;
+          }
+          if (!empty($join->arguments)) {
+            array_merge($data[$left_table]['table']['join'][$base_table], unserialize($join->arguments));
+          }
+        }
+
+        // warn if deprecated method of relationship addition was used (ie: through handlers)
+        if (isset($data[$base_table][$base_field]['relationship'])) {
+          watchdog('tripal_views',
+            'DEPRECATED: Currently using tripal_views_handlers to store relationship for %base => %left when you should be using tripal_views_joins.',
+            array('%base' => $base_table, '%left' => $left_table),
+            WATCHDOG_NOTICE);
+        }
+        // add relationship entry
+        $fake_field = $base_table . '_to_' . $left_table;
+        $data[$base_table][$fake_field] = array(
+          'title' => "$base_title => $left_title",
+          'help' => "Joins $base_title to $left_title",
+          'relationship' => array(
+            'handler' => $join->relationship_handler,
+            'title' => t("$base_title => $left_title"),
+            'label' => t("$base_title => $left_title"),
+            'real field' => $base_field,
+            'base' => $left_table,
+            'base field' => $left_field
+          )
         );
-        if ($handler) {
-          $data[$left_table]['table']['join'][$base_table]['handler'] = $handler;
+        if (!empty($join->arguments)) {
+          array_merge($data[$base_table][$fake_field]['relationship'], unserialize($join->arguments));
         }
       }
     }
   }
 
+  ddl('cleared view cache');
+
   return $data;
 }
 
 /**
+ * Implements hook_views_data_alter().
+ * Used to add Chado <-> Node Joins & Relationships
+ *   since you need to add to the $data['node'] to do this
  *
  * @ingroup tripal_views
-
+ */
 function tripal_views_views_data_alter(&$data) {
-    // D7 TODO: Check DBTNG changes work
-    $tvi_query = db_query('SELECT * FROM {tripal_views}');
 
-    // iterate through the views that we manage
+    // ADD IN NODE JOINS & RELATIONSHIPS
+    // D7 @todo: Create custom handler to allow join from Node => Base (ie: organism)
+    //           with the addition of a single relationship
+    // D7 @todo: Create custom handler to allow join from Base (ie: organism)
+    //           with the addition of a single relationship
+    // D7 @todo: Add support for Mview <-> Node joins and relationships
+    $tvi_query = db_query('SELECT * FROM {tripal_views} WHERE base_table=1');
     foreach ($tvi_query as $tvi_row) {
 
       //ids we'll use for queries
-      $mview_id = $tvi_row->mview_id;
       $setup_id = $tvi_row->setup_id;
-
-
-      // iterate through the columns and alter the existing data array for
-      // joins to other tables
-      // D7 TODO: Check DBTNG changes work
-      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
-      $joins = db_query($sql, array(':setup' => $setup_id));
-      foreach ($joins as $join) {
-        $left_table = $join->left_table;
-        $left_field = $join->left_field;
-        $base_field = $join->base_field;
-        $base_table = $join->base_table;
-
-        // add the recipricol join entries for each column
-        if (array_key_exists($left_table, $data) and $base_table != 'node') {
-          $data[$left_table]['table']['join'][$base_table] = array(
-            'left_field' => $base_field,
-            'field' => $left_field,
-          );
-        }
-      }
+      $base_table = $tvi_row->table_name;
+      $linker_table = 'chado_' . $base_table;
+      $base_title = ucwords(str_replace('_', ' ', $base_table));
 
       // add in joins to the node tables if the Chado schema is local
       if (tripal_core_chado_schema_exists()) {
-        $base_table = $tvi_row->table_name;
-        $linker_table = 'chado_' . $base_table;
         // if a node linking table exists then add in the joins
         if (db_table_exists($linker_table)) {
 
+          // Adds content (node) fields to chado base table field lists automatically
           $data['node']['table']['join'][$linker_table] = array(
             'left_field' => 'nid',
             'field' => 'nid',
           );
+          $data[$linker_table]['table']['join'][$base_table] = array(
+            'left_field' => $base_table . '_id',
+            'field' => $base_table . '_id',
+          );
           $data['node']['table']['join'][$base_table] = array(
             'left_table' => $linker_table,
             'left_field' => 'nid',
             'field' => 'nid',
           );
+
+          // Adds in a chado base table => node relationship
+          // This allows controlled joining to multiple nodes per line
+          // Use Case:  link to feature and organism nodes on a feature listing
+          // D7 todo: a custom relationship handler to get from feature.organism_id => organism node
+          //      without 1st needing to add relationship to organism table
+          $base_field = $base_table . '_id';
+          $data[$linker_table][$base_field] = array(
+			      'group' => $base_title,
+			      'title' => $base_title . 'Node',
+			      'help' => "Links $base_title to it's node.",
+			      'relationship' => array(
+			        'handler' => 'views_handler_relationship',
+			        'title' => t("$base_title => Node"),
+			        'label' => t("$base_title => Node"),
+			        'real field' => 'nid',
+			        'base' => 'node',
+			        'base field' => 'nid'
+			      ),
+			    );
+
+          // Add Chado fields to a node-based view
+          // This will only be done with relationships
+          $base_field = $base_table . '_id';
+          $data['node'][$base_field] = array(
+			      'group' => $base_title,
+			      'title' => $base_title,
+			      'help' => "Links node to chado $base_title.",
+			      'relationship' => array(
+			        'handler' => 'views_handler_relationship',
+			        'title' => t("Node => $base_title"),
+			        'label' => t("Node => $base_title"),
+			        'real field' => 'nid',
+			        'base' => $linker_table,
+			        'base field' => 'nid'
+			      ),
+			    );
+
         }
       }
     }
+
     return $data;
 }
-*/
 
 /**
  * Implementation of hook_views_plugins().
+ */
 function tripal_views_views_plugins() {
   $tc_path = drupal_get_path('module', 'tripal_views');
 
@@ -699,32 +603,6 @@ function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
   $view->attachment_after = $form;
 }*/
 
-/**
- * Implementation of hook_views_pre_execute().
-function tripal_views_views_pre_execute(&$view) {
-  // if the base table is a chado table then we want to set the
-  // search path so it can find all of the tables.
-  // this will break views that use tables that have the same name
-  // as chado tables (e.g. contact).
-  $desc = tripal_core_get_chado_table_schema($view->base_table);
-  if ($desc) {
-    tripal_db_set_chado_search_path('chado');
-  }
-}
-*/
-
-/**
- * Implementation of hook_views_post_render().
-function tripal_views_views_post_render(&$view, &$output, &$cache) {
-  // if the base table and the query is completed we want to set
-  // the search path back to the default.
-  $desc = tripal_core_get_chado_table_schema($view->base_table);
-  if ($desc) {
-    tripal_db_set_default_search_path();
-  }
-}
-*/
-
 /**
  * the Download Views data export form
 function tripal_views_data_export_download_form(&$form_state, $view, $display_id, $args) {

+ 1 - 0
tripal_views/views/handlers/tripal_views_handler_filter_no_results.inc

@@ -46,6 +46,7 @@ class tripal_views_handler_filter_no_results extends views_handler_filter {
 
   function query() {
     global $base_url;
+    $jquery_loaded = FALSE;
 
     // Check that all filter types don't return arrays
     // If they do then just show results by default b/c there is no way to tell the