Setup
Right now I've added a "caption" field to my "Image" file types. On my "blog" content type I've added a media selector "field_image" so that users can upload images with captions.

Desired outcome
I'd like to output those images and captions using views. So I create a view of "Type: Content". I add the "field_image" field and get the images displaying correctly. Then I want to add the "caption" field, so I have to add the "File Usage: File" relationship to the view.

Problem
As soon as I add the "File Usage: File" relationship, duplicates start appearing in the view.

Thoughts on how this might be possible? I've also tried creating a view of "Type: File" but I'm unable to successfully add the "Content: NID" argument so that I can restrict it to the page currently being viewed.

Comments

Dave Reid’s picture

Status: Active » Fixed

Don't use the File usage relationship. Use the Content: Image (field_image:fid) relationship (make it required so that it won't process nodes that don't have any image data) and then add the caption field using that relationship.

bryancasler’s picture

Hi Dave, that relationship doesn't seem to be an option (screenshot). I did figure out a way to get this working, with some limitations, but you were faster than I could follow up :)

Instead of adding the image field (screenshot) add the "File Usage: File" relationship and then add "File: rendered file" field (screenshot). Then add the contextual filter "Content: NID" with the option "Provide default value" and "Content ID from URL".

I know this is a horrible way to go about doing this, but I go on vacation tomorrow and I just need it to work well enough for the next week while I'm gone.

I'm using the unstable3 release, should I switch to the dev release and try again?

Dave Reid’s picture

Status: Fixed » Postponed (maintainer needs more info)

Version of file_entity should not matter. I'm not sure why you don't have the correct relationship available to select from - maybe you need to ensure you're running the latest version of Views? Is your image field the 'Quick image upload' field?

bryancasler’s picture

Thanks for the quick respond Dave, I've been running...
Views from 2/8 "version = "7.x-3.1+56-dev"
File entity 1/12 "version = "7.x-2.0-unstable3"

To see if outdated modules were the cause I just updated it to...
Views from 2/20 "7.x-3.2"
File entity from 2/21 "7.x-2.0-unstable3+17-dev"

Quick image upload is not the correct field. The one I'm looking for is called "Image" and is "field_image". Unfortunately after updating "Content: Image (field_image:fid) relationship" is still not available.

bryancasler’s picture

Dave, do you think this might be the problem? The field in question is a "Multimedia Asset" (screenshot).

Dave Reid’s picture

That would definitely be the problem.

Dave Reid’s picture

Title: Adding fields to a file type can cause unavoidable duplicates in views » Unable to add media field Views relationship
Project: File Entity (fieldable files) » D7 Media
Version: 7.x-2.0-unstable3 » 7.x-2.x-dev
Component: Code » Media field
Assigned: Unassigned » Dave Reid
Status: Postponed (maintainer needs more info) » Active

I have this tracked down to a bug in the media field Views integration. I'm fixing it shortly.

Dave Reid’s picture

Status: Active » Fixed

I've tested and fixed this for 7.x-2.x and 7.x-1.x. A new dev release for testing should be available in 12 hours or less.
http://drupalcode.org/project/media.git/commit/8a189d2
http://drupalcode.org/project/media.git/commit/4e33b20

bryancasler’s picture

That looks to have completely fixed it. Thanks Dave!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

cc