Question

I'm getting duplicate nodes in a a view I've created in Drupal. It appears the issue is related to the way the join is done in views for the node_access table.

Using devel, I see the following query:

    SELECT node.nid AS nid,
           node.language AS node_language,
           node_data_field_weekend.field_weekend_value AS node_data_field_weekend_field_weekend_value,
           node_data_field_weekend.field_weekend_value2 AS node_data_field_weekend_field_weekend_value2,
           node.type AS node_type,
           node.vid AS node_vid,
           node_data_field_weekend.field_weekend_loc_nid AS node_data_field_weekend_field_weekend_loc_nid
      FROM node node
 LEFT JOIN content_type_wwme_weekends node_data_field_weekend ON node.vid = node_data_field_weekend.vid
INNER JOIN node_access na                                     ON na.nid = node.nid
     WHERE (na.grant_view >= 1 AND
           (
           (na.gid = 0 AND na.realm = 'all') OR
           (na.gid = 0 AND na.realm = 'domain_site') OR
           (na.gid = 0 AND na.realm = 'domain_id'))) AND
           (
           (
           (node.type IN ('wwme_weekends')) AND
           (node.status <> 0 OR
           (node.uid = 0 AND 0 <> 0) OR 0 = 1)) AND
           (DATE_FORMAT(STR_TO_DATE(node_data_field_weekend.field_weekend_value, '%Y-%m-%dT%T'), '%Y-%m-%d') > '2010-01-10') )
  ORDER BY node_data_field_weekend_field_weekend_value ASC LIMIT 0, 5

The join to the node_access table is causing the other records to duplicate because there are multiple node_access records to a node, one with the realm of domain_site and one record with the realm of domain_id.

The data sort of looks like this (with some columns cut for brevity):

nid     gid    realm        grant_view  grant_update    grant_delete
73      0      domain_id    1           1               1
73      0      domain_site  1           0               0
988     0      domain_id    1           1               1
988     0      domain_site  1           0               0
90      0      domain_id    1           1               1

What purpose does the realm fit? How are these records populated, and most importantly, how can I fix this? Is the SQL right?

Was it helpful?

Solution 2

The answer apparently was a lot more mundane than I was thinking:

Use the "distinct node" configuration option under views, this takes out dupes.

OTHER TIPS

I think the realms fit in when you have a drupal site with multi site access turned on and your using the Domain Access module (http://drupal.org/project/domain) If you don't need the Domain Access module uninstalling might solve some of this. If you do need it you will most likely need to add a Filter to your view with the Node access: Access and/or use the Domain Views module. That should get you headed in the right direction. I've never worked with these modules myself. I just went through the module code and project pages. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top