Content type: a standard page with Image field (unlimited values)

I created a view which should display only image and its name. Filename is in file_managed, so I created a relationship to File and added the File Name field. So there are two fields in the view: Image and File Name. The view uses Grid display and has unchecked "Display all values in the same row" for Image field to better illustrate the issue (without unchecking the isue still exists, only looks more strange)

Issue: instead of 3 images, there are 9 images displayed, because each image is repeated 3 times. That's because the LEFT JOIN with file_managed table is missing an additional condition:

AND (field_data_field_image.field_image_fid = file_managed_file_usage.fid)

If you add the above condition (in WHERE clause) then there is one-to-one relation between each image and its name and there are 3 images displayed (tested directly in database, because I don't know how to have Views use the additional restriction.

Is it possible to somehow insert such additional restriction to a View?

Attached screenshot and view

P.S. I was using Media to insert the images to the node, but I think the same happens without Media module, using just plain Image

CommentFileSizeAuthor
view.txt7.52 KBraincloud
scr.png24.02 KBraincloud
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

couturier’s picture

Status: Active » Closed (won't fix)

I believe that you would be able to fix the duplicates problem by correctly configuring the View in the UI. If you need more assistance, please update this issue with your current problem.

IWasBornToWin’s picture

Status: Closed (won't fix) » Active

I believe that you would be able to fix the duplicates problem by correctly configuring the View in the UI

Would you mind displaying the correct way in which you believe it can be fixed?

couturier’s picture

@IWasBornToWin can you please tell me the specifics of your Views setup? The issue described by raincloud is complex and may not apply to you personally.

IWasBornToWin’s picture

Mine was a taxonomy related to nodes issue. I solved it by choosing "distinct" in query settings.

couturier’s picture

Exactly. You can use "distinct," you can use "reduce duplicates" in the filter criteria. There are several ways to configure things. Also, some people have noted bugs in the 7.x-3.5 Views release that make the published filters or sort criteria return duplicates. We're still working on that, but you can play around with removing various things to see what does and does not create duplicates if you still have issues. Once Drupal 8 is released, then we'll start all over with the duplicates question, I am sure.

cbrasfield’s picture

I have a relationship set with a taxonomy term that filters by a value within a multi-value field. It returns all of the values of the field for which the result is found. Distinct does not work.

couturier’s picture

I really think it is a bug that has not been fixed yet. It appears to have started upon upgrade to 7.x-3.5. I had to simplify my Views for now to get things working again. Follow the progress at this issue: Duplicate rows are in the view's result set (was: distinct doesn't work)

lykyd’s picture

I had the same problem using a relationship on a classic cck field. The field was multiple so it caused duplicates in my view result. Finally I solved the problem by setting an option I had never noticed.
In Relationships, I clicked on my relation item and there's a "Delta" option in the edit. I set it to "1" because I only need to get the first Image (my multiple field content is an image). That killed duplicated results, but it works because I just need to get one of all pictures.

DeNelo’s picture

I have a similar problem (running Views 3.6).
My Content type has a list of files, and I list those files. I add relationship to "File", and I add Filesize to the field list.
I then get every combination of filename and filesize (each filesize of each file in the list is repeated with each filename).
I have chosen Distinct (and True Distinct). I've also tried appliying the workaround in #8, but no luck so far.

Mołot’s picture

I'm currently working on making views able to understand many-fields joins in http://drupal.org/node/1966328
If this is done, you could build your bugfix on top of mine.

hachesilva’s picture

#6 by @pthurmond works like a charm, thanks for this. I was going nuts with the duplicates, almost 2 days gone trying to workaround this issue.

lovecookie’s picture

#8 by pthurmond worked for me as well, Drupal 7. Thank you!!!

MO-2’s picture

MO-2’s picture

Issue summary: View changes

PS

kkalaskar’s picture

same problem here.
I set In view->query settings, i have set it to distinct.
and it resolve.

谢艳’s picture

Issue summary: View changes

Try various methods, finally #14 works for me

MXT’s picture

#14 is the only method that resolves for me also

Gik000’s picture

#8 worked for me ...
nice job!

raffi’s picture

#8 thanks

mocasalter’s picture

#14 worked for me, thanks!

C.E.A’s picture

Here are workaround solutions:

1) In the Pager section:
Use pager:Display a specified number of items | 1 item

or

2) under advanced section, goto: Query settings and check the box distinct

0r

3) you can use "reduce duplicates" in the filter criteria.

or

4) You can try this module: https://drupal.org/project/views_distinct

AndraeRay’s picture

Thanks #21!

I'm using query settings distinct. It warns about performance implications, but l haven't seen any noticeable difference.

You can see how long your query takes to run by going to views settings and enabling "Show performance statistics". This can help you to compare.

laura.gates’s picture

I believe that I've found another workaround that might come in handy:

In my view (D7 views v: 7.x-3.16)., I wanted to Display all values in the same row using a relationship to an entity reference. However, even with Query settings > Distinct selected I was still getting duplicates. Turning on aggregation removed the ability for my data to Display all values in the same row but also removed my duplicates.

So upon reading:

(and probably a few others that I missed)

I decided to try the NID and Count that was presented in https://www.drupal.org/node/603868#comment-4421144 but with a few extra steps....

I made the relationship that caused my duplicates required. Then added NID. NID was then ranked 1st in field order. Turned aggregation on and changed NID to count. This threw off the display of my body field so I had to change Body group column needs to be set to value. summary and format must be selected under *group columns (additional).

Once these steps are complete, turn OFF aggregation and the duplicates were removed.

renatog’s picture

Status: Active » Reviewed & tested by the community

#21 really makes sense

Thanks @C.E.A

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

dovlijaner’s picture

Distinct doesn't work for me,. but works if I set "delta" in relationship like in #9

Lukas von Blarer’s picture

I have a dirty hack for D8: https://gist.github.com/luksak/0907196a41315b5876f9d630a554f41c

It won't work with pagination an might cause unexpected issues, but in my case it solves the issue.