D7 Views 3: Filter by relationship based on nid and uid I have a content type 'contest' that users submit guesses on. The guesses are entities that have uid and nid properties (and of course their own primary key, gid) to record the user and the contest to which they belong.

How can I display only contests on which a given user has submitted guesses?
A similar problem might be how to return only nodes of a certain type that a given user has commented on.

By using this within hook_views_data and setting the query to distinct (which I'd also prefer not to have to do) within the Views UI, I was able to confine the results to nodes that have guesses whose nid property match - but I can't figure out how to confine the results to nodes with guess entities whose nid AND uid properties match:

$data['node']['nid'] = array(
    'relationship' =&gt; array(
        'handler'        =&gt; 'views_handler_relationship',
        'base'           =&gt; 'entity_guess',
        'base field'     =&gt; 'nid',
        'title'          =&gt; t('Has guesses'),
        'label'          =&gt; t('contests with guesses'),
    ),
);


Thanks so much!
I ended up achieving the result that I wanted with hook_views_query_alter:

function site_views_query_alter (&amp; $view, &amp; $query)
{
  if ('block_3' == $view-&gt;current_display) {
    $account        = SiteUser::loadByID(arg(1), TRUE);
    $query-&gt;where[] = array(
      'conditions' =&gt; array(
        array(
          'field'    =&gt; 'node.nid',
          // Return just the IDs
          'value'    =&gt; SiteContest::getContestsPlayedBy($account, TRUE),
          'operator' =&gt; 'in',
        ),
      ),
      'args'       =&gt; array(),
      'type'       =&gt; 'AND',
    );
  }
}