title: Show Content in a View if content Author has the same entity reference value as the logged in user
body: <p>Title pretty much explains it. I have a user entity reference field (Node) called &quot;Company&quot;. I want to show all content in a view where the author of that content has the same &quot;company&quot; value as the logged in user. I'm getting a little confused with the relationships to achieve this.</p>
  <p>Ok, I was able to get this working based on Kien's answer. If using Entity Reference 7-x.1.5 Instead of 'field_company_nid', the correct column name was 'field_company_target_id'</p>
  <code>
  <pre><code>/**
   * Implements hook_views_query_alter().
   */
  function your_module_views_query_alter(&amp;$view, &amp;$query) {
    if ($view-&gt;name == 'article' &amp;&amp; $view-&gt;current_display == 'page') { // replace 'article' and 'page' by your view's machine name and display's machine name
      $author_join = new views_join();
      $author_join-&gt;table = 'field_data_field_company'; // 'field_company' is machine name of the user's field referencing to Company
      $author_join-&gt;field = 'entity_id';
      $author_join-&gt;left_table = 'node';
      $author_join-&gt;left_field = 'uid';
      $author_join-&gt;type = 'left';
      $view-&gt;query-&gt;add_relationship('author_company', $author_join, 'node');
  
      $current_join = new views_join();
      $current_join-&gt;table = 'field_data_field_company'; // 'field_company' is machine name of the user's field referencing to Company
      $current_join-&gt;field = 'field_company_target_id';
      $current_join-&gt;left_table = 'author_company';
      $current_join-&gt;left_field = 'field_company_target_id';
      $current_join-&gt;type = 'left';
      $view-&gt;query-&gt;add_relationship('current_company', $current_join, 'author_company');
  
      global $user;
      $view-&gt;query-&gt;where[1]['conditions'][] = array(
        'field' =&gt; 'current_company.entity_id',
        'value' =&gt; $user-&gt;uid,
        'operator' =&gt; '='
      );
    }
  }
  </code></pre>
  </code>