How would one go across relationships within Views to find other siblings with the same relation.

e.g.

A ->- B
C ->- B
D ->- B

You're on A and would like to see all related to B but not including itself. e.g. (C & D).

Is this possible with relationships in Views?

CommentFileSizeAuthor
#10 dump_1149382.zip93.21 KBchx

Comments

chx’s picture

Well, it would be possible to create an integration which allows to retrieve C and D in separate rows -- in one row, that might be very very tricky due to SQL mandating a fixed number of columns.

jdelaune’s picture

Yeah separate rows is fine. I know how to do this in SQL but I'm not sure how one would go about it within Views or if support is even there for it. You would do a JOIN to find the endpoint of A (B) and then do a subselect to get any B endpoints to find C and D.

Seraphin42’s picture

And is it possible to add in views a relationship like this : i'm the node 1 and i want to find each content related to me (1) ?
Actually, with the relationship, I get all contents related to my content type.

I don"t know if i'm clear, and maybe I need to learn a little bit more how views and drupal works .. but I've a very newbie point of view.

naught101’s picture

I'm having difficulty figuring out how views even could be used in a meaningful way with relation. I mean, what if your relations are relating nodes to users or something? How will the view display the data? Would you use a node view, or a user view? I could really use a detailed use-case, if anyone can think of one (using A and B without defining some example entity types is just confusing to me).

Seraphin, you may be running in to #1147976: Relationships always required in views

Oh, and subscribe +1

dpi’s picture

Issue tags: +views

It seems the views integration shows all predicates that are related. Instead of limiting to the predicate selected in views relationship. Unsure if this is because of #1147976: Relationships always required in views.

ofridagan’s picture

subscribing
I'm actually wondering if there is any integration for views in relation...

Daniel _Bun’s picture

YES
subscribing
I'm actually wondering if there is any integration for views in relation...
..

alanom’s picture

I believe you can do jdelaune's original request this in Views and Relation as they stand. Please correct me if I've misunderstood anything, this seems to work for me in basic testing.

Use case: a family tree. Granny Greta [nid:1] is parent to Mama Mary [nid:2] and Papa Peter [nid:3]. Mama Mary is parent to Lil Lucy [nid:4], Papa Peter is parent to Small Simon [nid:5] and Tiny Timothy [nid:6].

We're putting a Views block called 'Grandchildren' onto Granny Greta's page /node/1

  • Relationships: 'Relation: Parent (node->-node)', 'Required' ticked, 'Position...' set to 'Target'.
  • Contextual filters: Content nid, using relationship: 'Parent'. So, Views uses each of Granny Greta's children as an argument.
  • Fields: Content: Title. using relationship: Parent.

So, views takes nid 1. In the contextual filter, for each node that has a Parent relationship to nid 1 (nids 2 and 3), it runs through the fields. Since these are also set to use the relationship, it shows each child of nid 2, then each child of nid 3. End result:

Grandchildren:
**************
Lil Lucy
Small Simon
Tiny Timothy

This seems to work for me but I only did very basic testing. Note that this can show duplicate fields if you've got a relationship structure where it's possible for x ->- y and y ->- x or x ->- a ->- y and also x ->- b ->- y. If you wanted great grandchildren or beyond... then my head starts to hurt, maybe you could do it with a bunch of nested attachment views?

chx’s picture

Status: Active » Fixed

By now, the only reason this didnt work was the artificial step of not adding views relationships from nonbinary relation types. The attached dump lists four siblings for me.

chx’s picture

StatusFileSize
new93.21 KB
pkcho’s picture

Thanks for fleshing this out a bit.

I was encountering duplicate results in blocks probably due to what you explained x > y and y < x, but I wasn't sure how to filter the view to allow for only unique instances.

Anyone have a clue?

Thank you,
Joe

chx’s picture

There's a distinct in views...

alanom’s picture

...in Views UI 'distinct' is a checkbox hidden under 'Query settings', it gives a similar effect to the old D6 module 'Views Exclude Previous'. (took me a while to find it after upgrading)

pkcho’s picture

thank you! that helped.

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