Hook_views_query_alter: adding condition with entity reference value I need to filter a table result based the current user.

I added this condition in my hook_views_query_alter

function my_module_views_query_alter(&amp;$view, &amp;$query) {
  global $user;
  if ($view-&gt;name == 'preventivi' &amp;&amp; $view-&gt;current_display == 'page_3') 
  {
    // $view-&gt;query-&gt;add_where(1, $user-&gt;uid, 33, '=');
    $view-&gt;query-&gt;add_where(1, "field_data_field_installatori_reference.field_installatori_reference_target_id", $user-&gt;uid, '!=');

    // dpm($view);
    //dpm($query);
  }
}


but I can't find the correct value of target_id to insert in the condition.
Any suggestion?
This comment save my life!
https://api.drupal.org/comment/49458#comment-49458


  Be careful to add the table, even if You added the field in the view
  UI :


I added         

$view-&gt;query-&gt;add_table("field_data_field_installatori_reference");


and then I could access to my field:

$view-&gt;query-&gt;add_where(1, "field_data_field_installatori_reference.field_installatori_reference_target_id", $user-&gt;uid, '!=');