My node view filtered by taxonomy term results in duplicates by user roles. That is I simply want to list the node titles and teasers for a particular taxonomy term. If the user I am logged in only has 1 role the display is fine. However, if the user has more than one role then the my view has the same number of duplicate node title and teaser displays. This is weird, what am I doing wrong? I am using a filter by Term.

Here is the SQL from a preview of the view....

SELECT node.nid AS nid,
node.title AS node_title,
node_revisions.teaser AS node_revisions_teaser,
node_revisions.format AS node_revisions_format,
term_node_value_0.weight_in_tid AS term_node_value_0_weight_in_tid
FROM drupal_node node
INNER JOIN drupal_term_node term_node_value_0 ON node.vid = term_node_value_0.vid AND term_node_value_0.tid = 1
LEFT JOIN drupal_node_revisions node_revisions ON node.vid = node_revisions.vid
WHERE term_node_value_0.tid = 1
ORDER BY term_node_value_0_weight_in_tid ASC

Comments

dawehner’s picture

Component: node data » taxonomy data
Status: Active » Postponed (maintainer needs more info)

This looks like you are not using taxonomy: all terms. You have to use this field to remove duplicates...

For this kind of reasons its always important to export your view!

webservant316’s picture

I am using
Filters
Taxonomy: Term = Homepage
with
Operator 'is all of' Hompage and reduce duplicates checked.

However, I still get a multiples equal to the number of roles of the logged in person. So if someone has more than 1 role then each node title and teaser gets listed that many times in the view.

Weird. I am looking at the query and having trouble understanding why this is happening.

dawehner’s picture

Status: Postponed (maintainer needs more info) » Active

Ah do you use any kind of node access system?

If yes, apply http://drupal.org/node/284392 #397

This will fix your issue there

webservant316’s picture

Status: Active » Postponed (maintainer needs more info)

Still fighting with this.
Drupal 6 and Views 6.x-2.8.
Here is the view query...

SELECT node.nid AS nid, node.title AS node_title FROM drupal_node node

This simple view list the titles of all nodes in my database. However, if the use is in multiple (x) roles, it lists the title (x) times! Why!! Note, I also have a taxonomy, 'ACCESS' defined for access permissions using the TAC module. The taxnomy is set to allow multiple selections, but none required. Here is a curious thing, all the node titles repeat (x) times if I have made no assignment of the node to a term in the 'ACCESS' taxonomy. However, if I have made an assignment of a node to a term in the 'ACCESS' taxonomy then the node title will only be diplayed 1 time!

Wow what is going on here? Is the error in Taxonomy, TAC, Views, or myself?

webservant316’s picture

Whoa. I never saw so many posts! How do I know that is the right patch for me? There are numerous patches before #397 and a few after. I am running Drupal 6.15 with Views 6.x-2.8.

dawehner’s picture

Status: Postponed (maintainer needs more info) » Fixed

Yes this bug was reported many times... Use http://drupal.org/files/issues/284392-simplify-with-tests-db_distinct_fi...
This patch works fine.

webservant316’s picture

A summary of my research into the duplicate nodes in Views bug.

1. When I saw this bug I started a post at http://drupal.org/node/715074 titled 'Node view filtered by taxonomy term results in duplicates by user roles!?'. Someone directed me to another post...

2. So I joined the mega post at http://drupal.org/node/284392 titled 'db_rewrite_sql causing issues with DISTINCT'. Various patches were suggested with the leader seeming to be #397. I was ready to install the patch when another person directed me to yet another thread.

3. So I also joined the post at http://drupal.org/node/681760 titled 'Eliminating duplicate nodes caused by node_access table joins'. Frankly this guys patch seemed to make more sense to me using the sub-select instead of the DISTINCT to get rid of duplicates which shouldn't have been there in the first place.

4. While meditating over this issue with extremely limited understanding it seemed to me that duplicates are being created in the Views module because joins of various nature are included in the query which the views module does not seem to be aware of. In my case I figured out that my node table was joined with tables from TAC and roles because the number of duplicates matched the number of roles that my current user was linked to. The error here, again, is that the test for permission to access the node should result in one node returned, not one node for each role I am a member of.

5. And while waiting to hear back from my posts on this issue, I had to continue with my work and while creating yet another View I noticed that the Views interface provides the option of 'distinct' yes/no. Curious. The note by this option says 'This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.' It seems to me that the author of the Views module recognized that sometimes duplicates would appear because of mysterious joins or whatever beyond their control and so they simply added the distinct flag to deal with the issue. In the end I simply used this flag, inspite of the performance warnings, and all the duplicates disappeared in my Views without any patch. This seemed safer for now rather than patching core. As for performance issues, I can understanding the warning because in my case my Views are reading NODE X USER-ROLES instead of just NODE number of records.

6. I am thinking that using this distinct flag within the View interface itself might be about the same as using #397 anyway, so I plan to just use the flag instead of the patch unless someone explains something differently. Yet, the sub-select solution over at http://drupal.org/node/681760 seems to be headed in the direction of a solution for integration into the Drupal core.

7. Last question...I only observed the duplicates in my use of the Views module and so using the 'distinct' flag in the Views module cured my problem. However, do the patches in the threads above deal with possible duplication in others areas as well or is this problem limited to the Views module?

Well my Views problem is solved for now, but am I hoping that a solution is integrated into Drupal core that restores performance back to the optimum.

I think I transgressed by posting this exact comment on this post and two others. Please stop this thread and continue dicussion here, http://drupal.org/node/681760#comment-2636434. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.