3

I'm using Views 3 and Field collection 7.x-1.0-beta3. As a simplified example, say I've a field collection called Image - which itself has two fields, an image file and a text caption. My content type, Page, includes a multi-value field to reference one or more Image(s).

In my view, I want to list several Page nodes, and display the image file field taken from only the first of each node's referenced Image field collection entities.

This works, but...

I have one solution that does work but feels clunky and indirect: Add the Image collection-reference field, and use the multiple-value settings to restrict to the first value (a la this post). However, then I have to have a view mode for the Image field collection that prints only the image file field, in the desired image style.

What would be awesome:

I've tried a different route using the Relationships settings. I can add a relationship from node to its Image field collection. Then, I can add the image file field, pulling from the relationship. BUT, that creates a new result for each of the Image field collections being referenced... and I can't find an option to key the relationship off the first value only (similar to displaying only the first value when I'm just going through adding the field, in my "this works" solution above).

I realize this may be impossible - if Views can't create the necessary query? Just wondering if I have missed something though I've gone through the settings several times.

Edit: Drupal 6 / Views 2 does it!

Okay, I'm not crazy - see screenshot. I think that's exactly what I'm looking for here.

2

If you create a view with the field collection relationship this is possible. Besides the field with the image you need to add another field with the image delta. When you add this field exclude this from display.

In the views filter add a filter on this delta field and set this filter to equals 0.

Now you've got a view with just one (the first) image per node!

  • You are essentially correct; there's no need to add the image delta as a field in order to add it as a filter criterion though. This solution is actually what I ended up doing awhile back (but never got around to posting the answer here). – teatime Jun 8 '12 at 14:18
0

Hmmm. Apparently the Delta option (that I referred to in the D6 / Views 2 screenshot) is back again in the relationship configuration options - in Views version 3.3. Maybe it was just temporarily gone in a prior 3.x version...?

Setting this Delta to 1 would achieve the result I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.