I discovered this bug after updating Views recently to 7.x-3.1. Some of my views were not showing all the results that I expected. After looking at the query, I saw that it is because the Views have some joins that are not required (IE: left joins instead of inner joins), but domain_alter_node_query() always does an inner join.

I am using Drupal 7.8 and Domain Access 7.x-2.18.

Members fund testing for the Drupal project. Drupal Association Learn more


jojonaloha’s picture

Status: Active » Needs review
2.15 KB

Here is the proposed patch.

agentrickard’s picture

Status: Needs review » Needs work

Two issues:

1) The patch doesn't conform to coding standards.
2) How do you test this?

jojonaloha’s picture

1) I think the attached patch fixes this, I've read http://drupal.org/coding-standards and still had a hard time finding issues
2) I can describe my use-case a little which may help.
I have domain, domain_alias, domain_conf, domain_content, domain_settings and domain_theme enabled.

I have a few content types: We can call them "Event" and "Moderator"
A moderator is not a user but has a picture and a bio.
An event may have 1 moderator, using a nodereference field. It is an optional field.

I have a view that displays all Events for the current domain with the Moderator's picture, linked to their bio. I need the view to display all events even if there is no moderator. In my view I have a relationship to the Moderator which is not required.

This worked as I expected before the update to Views 7.x-3.1, after the update the query changed so that node_access is joined for Moderator as well. By using an INNER JOIN between node_access and the moderator, it was forcing the relationship to be required.

agentrickard’s picture

Status: Needs work » Needs review

Looks good. I see the logic here. This is a problem caused only for administrators.

What is odd to me is that core doesn't seem to use this pattern. From _node_query_node_access_alter():

      // The node_access table has the access grants for any given node so JOIN
      // it to the table containing the nid which can be either the node
      // table or a field value table.
      if ($type == 'node') {
        $access_alias = $query->join('node_access', 'na', '%alias.nid = ' . $nalias . '.nid');
      else {
        $access_alias = $query->leftJoin('node_access', 'na', '%alias.nid = ' . $nalias . '.entity_id');
        $base_alias = $nalias;

Do you have a View you can export and attach for testing?

jojonaloha’s picture

Here is my exported view, I stripped out some of the extra displays and client info.

agentrickard’s picture

agentrickard’s picture

Status: Needs review » Postponed
jojonaloha’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Postponed » Needs review
3.08 KB

Noticed there was a fix committed for that issue in Drupal 7, http://drupal.org/node/681760#comment-5701576

I've attached a patch based on the accepted patch from that issue. I'm not sure it solves this issue, but at least its a starting point based on what is (will be) in core.

agentrickard’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is this still an issue?

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

An updated version of this patch is in #1855298: EntityFieldQuery and Domain Access

Leeteq’s picture

(Cross-referencing since this issue has a very descriptive/clarifying title)