Say we have three content types: Organization, Service and Location. Both Service and Location have Node reference fields that contain an Organization. In fact, each Service or Location can reference multiple Organizations.

When the Service node ("Being Awesome") is viewed, we can see that it contains a node reference to the "Awesome, Inc" Organization. Here is the tricky part:

Can I create a View block, placed on the Service ("Being Awesome") page, and use an argument that gets all Location nodes that reference Organization "Awesome, Inc"? The Location nodes don't reference the Service nodes at all, but they have a node reference in common. Does that make sense? Is this even remotely possible? Might I be way too ambitious?

Comments

narayanis’s picture

This is where you'll want to play with Relationships in Views. It takes some experimentation, but your argument will be the Service you're on, and you'll create a relationship to the Organization, then another to the Location. This will allow you to display all Locations for the Organization.

jenna.tollerson’s picture

I am working on it. I know about relationships and have used them before, but I admit I have trouble fully understanding them.

narayanis’s picture

Post here if you get stuck and i'll try to find some time to create an example for you.

jenna.tollerson’s picture

I am not getting it. I can get one-to-one node relationships going, but I can't seem to figure out how to reach through a node to get to that third node.

I found this post where merlinofchaos talks about chaining relationships together, but that seems to be for a parent-child-grandchild hierarchy, which is not exactly the same as what I'm doing, and even if it was I can't get that last 10 percent of understanding that makes it really make sense to me. Feeling dumb.

Which is the reverse version of the relationship? I think part of my problem is I can't keep reverse and non-reverse relationships straight in my mind.

narayanis’s picture

You're doing it right, it just looks like Views and References can't handle it in the latest releases. However, you can get this patch for References (http://drupal.org/node/1083902#comment-4790656), or update to the latest dev of References. You may need latest dev of Views as well. Be sure to clear cache after updating.

I created the three content types, and use a shared field for the Org reference, called field_org. Once that's set up:

Contextual filter
Content:Nid -- this will be the Service nid

Relationships
Content: field_org
(field_org) Content: org (field_org) - reverse -- this is a chained relationship, apply the previous relationship to this one

Filter Criteria
(field_org) Content: Type (= Location)

Format
Teaser, using the second field_org relationship

That should do it! If you need an exported view, code is below

$view = new view;
$view->name = '123';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = '123';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = '123';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
$handler->display->display_options['row_options']['relationship'] = 'reverse_field_org_node';
$handler->display->display_options['row_options']['links'] = 0;
$handler->display->display_options['row_options']['comments'] = 0;
/* Relationship: Content: org (field_org) */
$handler->display->display_options['relationships']['field_org_nid']['id'] = 'field_org_nid';
$handler->display->display_options['relationships']['field_org_nid']['table'] = 'field_data_field_org';
$handler->display->display_options['relationships']['field_org_nid']['field'] = 'field_org_nid';
$handler->display->display_options['relationships']['field_org_nid']['required'] = 1;
$handler->display->display_options['relationships']['field_org_nid']['delta'] = '-1';
/* Relationship: Content: org (field_org) - reverse */
$handler->display->display_options['relationships']['reverse_field_org_node']['id'] = 'reverse_field_org_node';
$handler->display->display_options['relationships']['reverse_field_org_node']['table'] = 'node';
$handler->display->display_options['relationships']['reverse_field_org_node']['field'] = 'reverse_field_org_node';
$handler->display->display_options['relationships']['reverse_field_org_node']['relationship'] = 'field_org_nid';
$handler->display->display_options['relationships']['reverse_field_org_node']['required'] = 1;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['nid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['nid']['not'] = 0;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['relationship'] = 'reverse_field_org_node';
$handler->display->display_options['filters']['type']['value'] = array(
  'location' => 'location',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = '123';
jenna.tollerson’s picture

Normally I might have searched for a patch like that, except this time I was sure that the problem lay with me. Thanks so much for running that down. Updated to the dev version of References, cleared my caches, and carefully followed your instructions for creating my View, which were certainly helpful even with the fix in place. Now getting the results I was expecting. Definitely feeling less dumb. Thanks again for taking the time.