When using Taxonomy Term ID as arguments and a node has multiple terms checked the node gets displayed multiple times.

Ex if a node belongs to term 1 and 2 and i use ?q=myview/1 the node gets displayed twice.

Comments

merlinofchaos’s picture

Assigned: Unassigned » merlinofchaos
Category: bug » feature

Technically this is a feature, actually. There are use cases (and when I wrote that code I had those use cases in mind) where you want the node to show up under each term it is part of.

However, I can see why this feature might also be undesirable at times. There needs to be a switch.

Changing this to a feature request. It'll require a schema change. I'll have to ponder the least intrusive way to do it.

majomajomajo’s picture

thats not a bug , infact thats a hidden quality, like it a lot :)

merlinofchaos’s picture

Title: Taxonomy Term ID as arguments » Some Views can get rows repeated

Renaming this so it's a little easier for me to spot.

The solution will be to add a flag to set the view distinct, meaning each node will be returned once and once only. This is actually very easy to do thanks to the way the query builder is written (code can already do this, in fact, with a simple function call) but it requires a schema change, which sucks unfortunately.

pjdevries’s picture

The same kind of problem applies to views filtered on 'Author Role' (see dup post http://drupal.org/node/45185). Because I couldn't think of a reason why I would ever want duplicate rows in a result set, I hard coded a DISTINCT clause in the field and count_field properties of the _views_query class for the time being.

I do see now why this could considered be a (hidden) feauture taking taxonomy into account. I think there might be a reasonably elegant work around, not requiring a scheme change though: add 'DISTINCT' as special kind of filter.

pjdevries’s picture

I was a bit too hasty. The hard coded DISTINCT clause in the field and count_field properties of the _views_query class didn't solve my problems. Although it seemed at first, the solution appears to be a little bit more complicated than that. Adding the DISTINCT clause as I did, does get rid of duplicate nodes, but the query still returns rows from all 'Author Roles'. So I guess is that some kind of GROUP BY must be constructed, taking not only the node id but also the role id into account. Do correct me if I'm wrong.

Whatever the right solution may be, implementing it by means of a special filter type may still be a clean way to avoid schema changes.

merlinofchaos’s picture

but the query still returns rows from all 'Author Roles'.

I don't quite understand what you mean by this.

merlinofchaos’s picture

I added a Distinct filter in CVS, as someone suggested, which means I don't have to update the schema. Hooray!

merlinofchaos’s picture

Status: Active » Fixed
majomajomajo’s picture

Are you sure it is in cvs? I dont find any changes :( but on the other hand i dont know exactly were the modification is.

merlinofchaos’s picture

It's a filter named 'Node: Distinct'

battochir’s picture

Hey all,

I found something that is unusual and I'm not sure how to fix it. I was very excited about the 'views' module. It's an awesome idea. However, I was getting multiple views per listing. 3 per posting to be exact..I have no idea why 3. Anyway, I used the node:distinct filter. Problem solved I thought. Only half solved actually. Empty pages are being formatted as if the duplicate posts still existed. For example, lets say I have 10 postings per page. Without node:distinct I'd have 3 pages with 30 posts. 10 postings being dulicated 3 times each. When I use node:distinct I get 10 postings, which is correct. However, I STILL get 3 pages being formatted. Pages 2 and 3 are empty, but are being formatted anyway. How do I get this empty pages to stop being formatted? I've gone through the 'views' tables and I cannot figure out how to stop this behavior. Any ideas?

thanks,

wim

hadishon’s picture

Category: feature » support
Status: Fixed » Active

I'm having a similar problem.

I have the most recent cvs version with the "Node Distict"

I would like multiple Taxonomy Vocab/Terms Shown horizontally on the tabular view. When I try to accomplish this, views displays them vertically.

example:

What I want:

Vocab1 | Vocab2 | Title | Last Updated
____________________________________________
term1 | term2 | Node1 Title | Date/Time
term1 | term2 | Node2 Title | Date/Time

What I'm getting is:

Vocab1 | Vocab2 | Title | Last Updated
____________________________________________
term1 | term1 | Node1 Title | Date/Time
term2 | term2 | Node1 Title | Date/Time
term1 | term1 | Node2 Title | Date/Time
term2 | term2 | Node2 Title | Date/Time

Is this possible with the views.module? Let me know if I have to explain more or show a live example.

merlinofchaos’s picture

battochir: Your problem is definitely a bug, the count query needs to also use distinct, and it does not. I will fix.

hadishon: Unfortunately what you want to do is currently only possible through theming. Your problem isn't really about distinct, though that is part of it, but it has to do with needing the 'taxonomy term' field to be restricted to a particular vocabulary.

The sort of thing you want is coming up as a common interest, and I will work toward implementing it, but what you want makes a lot of assumptions about taxonomy that aren't necessarily true.

Still, one thing that it's becoming clear that Views needs is to be able to separate that taxonomy fields into specific vocabularies. That much, at least, I can do, and that might solve your problem. In other words, I can add each Vocabulary in the taxonomy as its own field, and it will display just a term from that vocabulary. It will still not be very useful if your node has multiple terms from that vocabulary, but for 1:1 relationships, it'll work very well.

Finally: I'd prefer it if you would re-enter this as a separate issue, since it turns out to be something very different, and it'll be easier for people to track.

battochir’s picture

merlinofchaos: thanks for your response. Good to know I'm not going bonkers. I was a bit concerned because this is on the 4.7 platform, which has not had an official stable release yet. Your module is pretty cool and gives alot of flexibility. Outside of this bug, for me, it's been all sunshine and blue skies!

ciao,

wim

battochir’s picture

merinofchaos: Maybe I spoke to soon. Unless I'm missing something you have NO bug here to fix. The error is my own. Here is what I mean. I was sitting down to fix this myself when I noticed the taxonomy filter. You see, I was getting 3 duplicates and I finally figured out why. Each node I was using was using 3 separate taxonomy terms, one each from 3 separate vocabularies. So, I was getting one duplicte per vocabulary/taxonomy term used per node. Under the 'Filters' setting, I had chosen 'Taxonomy Term:Is All Of'. That's wrong. When I changed it to 'Taxonomy Term:Is One Of', the problem went away. So, for others experiencing this problem, when using the 'Node:distinct' feature, be certain your vocabularies and taxonomies are also set to select only 'one of' something. That's my two cents. Am I right? I don't know. I do know the problem is gone. Sorry for not investigating further before I posted this issue.

thanks,

wim

merlinofchaos’s picture

Status: Active » Fixed

Oh that's very interesting. I think you were right the first time, though; the count needed to be set distinct as well. I set up a test and noted a definite irregularity. I've committed a fix to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)
micheleannj’s picture

Any way to get the fix for this as a patch? I need it for a live site and HEAD doesn't look stable enough!

Just to clarify that this is my problem:
I have nodes associated with terms from 3 different vocabularies. I have a term argument, which is working fine, but the nodes show up once for each vocabulary it's associated with (even though I'm filtering on the one vocabulary relevant to the view).

Thanks,
m