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

Files: 
CommentFileSizeAuthor
view.txt7.52 KBraincloud
scr.png24.02 KBraincloud

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)

pthurmond’s picture

So I found a really useful workaround that allowed me to fix this. I have posted the code snippet to DropBucket. Basically you implement a Drupal 7 query alter hook that checks all views queries for query comments that specify a groupby clause and field. Then it adds that groupby to the SQL query.

http://dropbucket.org/node/153

The source reference is in the comments on the page.

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’s picture

MO’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