How to create a View that shows other nodes that have the same entity reference as the current page I have job nodes, that relate to organizations. I want a sidebar block that will display other jobs that are related to the same organization.

I have tried a lot of different permutation of contextual filters and relationships, but so far I have not been successful.

I can only get the nid of the current node via a contextual filter, but that filters the content directly. I need just to get the referenced organization node, and then filter the view by that reference, but I can't seem to make it work.

(This question is for Drupal 7 with entity reference. The same question for Drupal 6 is here).
Here is a solution using the Entity Reference module to display other nodes that reference the same node that the current node references. No need for relationships, just follow these steps:


Make sure you're filtering the view by the content type you want to view a list of, not the one you're trying to reference.
Add a contextual filter using the entity reference field.
For the entity reference field, choose to provide a default value in PHP ¹.
Adapt the following code to your field names ² and save the contextual filter:     

$node = menu_get_object();
$referenced_node = $node->field_YOUR_FIELD_NAME['und'][0]['target_id'];
return $referenced_node;
Save the view and check it out.


¹Disclaimer: PHP should never be used in the UI due to concerns with security, performance, &amp; lack of version control. As a result, the proper way to implement this solution involves writing your own simple module that creates a block that passes the argument into the view as you render it in the block. I'm still including this because whether people ignore this warning or use it to write a module, hopefully it helped.

EDIT: If you also want to exclude the current node, you'll need to add an additional contextual filter for NID and make sure to select the "exclude" option.

² Not sure what your field names are? Install and enable the Devel module and visit a node. Click the 'devel' tab and navigate through the list to find your desired entity reference field.