have a BOOK that has many EDITIONS.
BOOKs has a multivalued entityrelation field "book2edition" to it's EDITIONs.

i need a view that only displays ONE EDITION per BOOK: the first one, the one with delta=0

is this possible?
i know well how to use relations but not how to filter on a delta.

tried the following
* added a edition view
* added reverse"book2edition" relation as "book"
* added "book2edition" relation as "backtoeditions"
* filtered by "book2edition:delta" with all 3 possible tables (edition and the two relations)

none did work, as expected.

huh, don't know if this is
* a feature request - if this cannot be done now any way
* a support request - if this can be done with views or contrib or magick


dawehner’s picture

Project: Views » Entity reference
Version: 7.x-3.x-dev » 7.x-1.x-dev
Component: Views Data » Code

I'm a bit confused whether you use the relation or the entityreference module, though i assume you use the second one,
because with relation this wouldn't be too hard, because you can get a relationship to the relation.

Let's move to entityreference, because they could implement a custom relationship handler which adds the condition.

edulterado’s picture

Title: Add a delta filter in the Views relationships » Filter by entityreference field relation delta
Category: feature » support

I´m using Entity Reference for accomplishing something very simliar.

I have a node PHOTO with an entityrelation field that defines a target bundle to the node GALLERY. This allows every node 'gallery' to have references from nodes of type 'photo'. I would like to make a view that only displays one PHOTO per GALLERY, but I didn´t find how.

I was able to do the same in D6 by using node reference and node referrer modules: I established a relationship with 'Node Referrer' and then I chose 'Delta = 1' for displaying only the first item that has a reference to GALLERY. Is there a similar way for doing this with entityrelation or it is still not yet implemented?

axel.rutz’s picture

so to summarize #2: seems to implement this in entityreference we can steal some code from references.module

Damien Tournoud’s picture

Title: Filter by entityreference field relation delta » Add a delta filter in the Views relationships
Category: support » feature

It seems to be a feature request then.

jorisx’s picture

Title: Filter by entityreference field relation delta » Add a delta filter in the Views relationships
Category: support » feature

I was curious if you found a way to do this?
I've kind of the same problem;

there are the content types; artist and paintings
every painting is linked to one artist via Entityreference
now i would like to create a view with all the artists and just show one random painting per artist... :)

any idea on how to acomplish this?

logaritmisk’s picture

Status: Active » Needs review
3.53 KB
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es). View

Shameless copy-and-paste from the relationships module. Haven't really tested it 100%, but I hope it works. Gonna test it more myself next week.

amitaibu’s picture

Please let know after tested so we can review.

RaF7’s picture

Tested this, looks like it works. Thanks!

jaydub’s picture

Ran into the same need for this feature which I also used in D6. Patch applies cleanly and works perfectly!

bradjones1’s picture

Status: Needs review » Reviewed & tested by the community

I'm regularly re-applying this patch after updating -dev and it's become pretty critical for some of my projects, so it'd be great to work toward getting this committed. Any maintainers willing to take a look? RTBC'ing to help move that along.

kaidjohnson’s picture

Exactly what we needed! #6 applies cleanly and works as designed.

+1 for RTBC


axel.rutz’s picture

Works like a charm, thanks logaritmisk!!

RTBC for me too.

Damien Tournoud’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
+      $join = $this->get_join();
+      if ($this->options['delta'] != -1 && $field['cardinality']) {
+        $join->extra[] = array(
+          'field' => 'delta',
+          'value' => $this->options['delta'],
+          'numeric' => TRUE,
+        );
+      }

This feels like it should just be an override of get_join()?

jpstrikesback’s picture

Status: Needs work » Needs review
3.6 KB
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es). View

I believe get_join() must be called specifically such as in ensure_my_table(). Here is a version that overrides get_join and then uses it in ensure_my_table().

rlmumford’s picture

Status: Needs review » Reviewed & tested by the community

Code style looks good and after extensive testing today everything works fine. Marking as RTBC.

atracht’s picture

I applied the patch, it appears to be working but I can't get it to display anything, like the name of the first delta term.

1. Added relationship: Term Name with delta one
2. Added filter Term Name with value set and relationship set to above. Nothing displays (empty), not showing no values found message.

If I remove the relationship it works, but filters on all delta values not just first, which is not what I want. I have multiple featured content blocks on a page filtered by a term reference. I want to have content to be able to be assigned to multiple terms but only display in the block for the first delta term so it can't show up in multiple blocks.

Right now I have a primary term reference field which can only take one value. And an "Additional" term reference field which can take multiple. I was just wanting to combine those into one field. Perhaps I should just keep it as two. Thoughts?

stupiddingo’s picture

Reroll of #14 to apply to latest dev. Line number updates only, no code changes, keeping RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: relationship_delta-1468862-17.patch, failed testing.

jaydub’s picture

Just a note that this patch no longer works with Views 7.3-14 at least for case of delta = 1 and it looks like it's due to issue that is now being worked on in: #2750453: Delta value 1 not handled

junaidpv’s picture

Status: Needs work » Needs review
3.69 KB

Patch in #17 will not get applied as file views/entityreference_handler_relationship.inc does not exist.

Attaching the corrected patch. No code changes.

I did not get a chance to test now, that I hope to update soon.

Status: Needs review » Needs work

The last submitted patch, 20: relationship_delta-1468862-20.patch, failed testing.