Index: views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v
retrieving revision 1.330
diff -u -r1.330 views.module
--- views.module	20 Feb 2009 23:02:09 -0000	1.330
+++ views.module	28 Feb 2009 23:13:48 -0000
@@ -38,7 +38,7 @@
   $arguments = array(
     'display' => array('view' => NULL),
     'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
-    'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
+    'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL),
   );
 
   // Default view themes
Index: modules/node.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/node.views.inc,v
retrieving revision 1.91
diff -u -r1.91 node.views.inc
--- modules/node.views.inc	2 Dec 2008 22:17:41 -0000	1.91
+++ modules/node.views.inc	28 Feb 2009 23:10:04 -0000
@@ -662,8 +662,12 @@
  */
 function template_preprocess_views_view_row_node(&$vars) {
   $options = $vars['options'];
-  $vars['node'] = ''; // make sure var is defined.
-  $nid = $vars['row']->nid;
+
+  // Make sure the variables are defined.
+  $vars['node'] = '';
+  $vars['comments'] = '';
+
+  $nid = $vars['row']->{$vars['field_alias']};
   if (!is_numeric($nid)) {
     return;
   }
@@ -676,7 +680,6 @@
   }
 
   $vars['node'] = node_view($node, $options['teaser'], FALSE, $options['links']);
-  $vars['comments'] = NULL;
   if (!empty($options['comments']) && function_exists('comment_render')) {
     $vars['comments'] = comment_render($node);
   }
Index: modules/node/views_plugin_row_node_rss.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/node/views_plugin_row_node_rss.inc,v
retrieving revision 1.4
diff -u -r1.4 views_plugin_row_node_rss.inc
--- modules/node/views_plugin_row_node_rss.inc	9 Jan 2009 17:16:34 -0000	1.4
+++ modules/node/views_plugin_row_node_rss.inc	28 Feb 2009 23:09:51 -0000
@@ -10,6 +10,10 @@
  * and formats it as an RSS item.
  */
 class views_plugin_row_node_rss extends views_plugin_row {
+  // Basic properties that let the row style follow relationships.
+  var $base_table = 'node';
+  var $base_field = 'nid';
+
   function option_definition() {
     $options = parent::option_definition();
 
@@ -19,6 +23,8 @@
   }
 
   function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
     $form['item_length'] = array(
       '#type' => 'select',
       '#title' => t('Display type'),
@@ -36,13 +42,22 @@
     // For the most part, this code is taken from node_feed() in node.module
     global $base_url;
 
+    $nid = $row->{$this->field_alias};
+    if (!is_numeric($nid)) {
+      return;
+    }
+
     $item_length = $this->options['item_length'];
     if ($item_length == 'default') {
       $item_length = variable_get('feed_item_length', 'teaser');
     }
 
     // Load the specified node:
-    $node = node_load($row->nid);
+    $node = node_load($nid);
+    if (empty($node)) {
+      return;
+    }
+
     $node->build_mode = NODE_BUILD_RSS;
 
     if ($item_length != 'title') {
@@ -71,7 +86,7 @@
       $node->body = $content;
       unset($node->teaser);
     }
-  
+
     // Allow modules to modify the fully-built node.
     node_invoke_nodeapi($node, 'alter', $teaser, FALSE);
 
Index: modules/node/views_plugin_row_node_view.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/node/views_plugin_row_node_view.inc,v
retrieving revision 1.1
diff -u -r1.1 views_plugin_row_node_view.inc
--- modules/node/views_plugin_row_node_view.inc	3 Sep 2008 19:21:29 -0000	1.1
+++ modules/node/views_plugin_row_node_view.inc	28 Feb 2009 22:34:26 -0000
@@ -11,6 +11,10 @@
  * Most of the code on this object is in the theme function.
  */
 class views_plugin_row_node_view extends views_plugin_row {
+  // Basic properties that let the row style follow relationships.
+  var $base_table = 'node';
+  var $base_field = 'nid';
+
   function option_definition() {
     $options = parent::option_definition();
 
@@ -22,7 +26,9 @@
   }
 
   function options_form(&$form, &$form_state) {
-    $form['teaser'] = array(
+    parent::options_form($form, $form_state);
+
+   $form['teaser'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display only teaser'),
       '#default_value' => $this->options['teaser'],
Index: plugins/views_plugin_row.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_row.inc,v
retrieving revision 1.1
diff -u -r1.1 views_plugin_row.inc
--- plugins/views_plugin_row.inc	3 Sep 2008 19:21:30 -0000	1.1
+++ plugins/views_plugin_row.inc	28 Feb 2009 23:10:16 -0000
@@ -27,10 +27,61 @@
     return !empty($this->definition['uses fields']);
   }
 
+
+  function option_definition() {
+    $options = parent::option_definition();
+    if (isset($this->base_table)) {
+      $options['relationship'] = array('default' => 'none');
+    }
+  }
+
   /**
    * Provide a form for setting options.
    */
-  function options_form(&$form, &$form_state) { }
+  function options_form(&$form, &$form_state) {
+    if (isset($this->base_table)) {
+      $view = &$form_state['view'];
+
+      // A whole bunch of code to figure out what relationships are valid for
+      // this item.
+      $relationships = $view->display_handler->get_option('relationships');
+      $relationship_options = array();
+
+      foreach ($relationships as $relationship) {
+        $relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
+
+        // If this relationship is valid for this type, add it to the list.
+        $data = views_fetch_data($relationship['table']);
+        $base = $data[$relationship['field']]['relationship']['base'];
+        if ($base == $this->base_table) {
+          $relationship_handler->init($view, $relationship);
+          $relationship_options[$relationship['id']] = $relationship_handler->label();
+        }
+      }
+
+      if (!empty($relationship_options)) {
+        $relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
+        $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
+        if (empty($relationship_options[$rel])) {
+          // Pick the first relationship.
+          $rel = key($relationship_options);
+        }
+
+        $form['relationship'] = array(
+          '#type' => 'select',
+          '#title' => t('Relationship'),
+          '#options' => $relationship_options,
+          '#default_value' => $rel,
+        );
+      }
+      else {
+        $form['relationship'] = array(
+          '#type' => 'value',
+          '#value' => 'none',
+        );
+      }
+    }
+  }
 
   /**
    * Validate the options form.
@@ -43,6 +94,16 @@
    */
   function options_submit($form, &$form_state) { }
 
+  function query() {
+    if (isset($this->base_table) && isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
+      $relationship = $this->view->relationship[$this->options['relationship']];
+      $this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
+    }
+    else {
+      $this->field_alias = $this->view->base_field;
+    }
+  }
+
   /**
    * Allow the style to do stuff before each row is rendered.
    *
@@ -56,6 +117,6 @@
    * of some form, but not always.
    */
   function render($row) {
-    return theme($this->theme_functions(), $this->view, $this->options, $row);
+    return theme($this->theme_functions(), $this->view, $this->options, $row, $this->field_alias);
   }
 }
Index: plugins/views_plugin_style.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_style.inc,v
retrieving revision 1.4
diff -u -r1.4 views_plugin_style.inc
--- plugins/views_plugin_style.inc	8 Oct 2008 00:14:01 -0000	1.4
+++ plugins/views_plugin_style.inc	28 Feb 2009 22:34:14 -0000
@@ -193,5 +193,12 @@
     }
     return $errors;
   }
+
+  function query() {
+    parent::query();
+    if (isset($this->row_plugin)) {
+      $this->row_plugin->query();
+    }
+  }
 }
 
