I've defined a directional relation between two node types (call them A and B) and added some relations between A and B nodes. I simply want to create a View of B nodes that are part of at least one relation.
I created a node view, and added the node -> relation relationship, but it appears that this relationship is not working, and no information is actually getting returned about the relations. For instance, if I add the 'relation: number of rows' field, it returns 0 for every node, even though several them have relations defined.
Am I missing something, or is this a bug?
Comments
Comment #1
marcusx commentedSame problem here.
I think this is a bug in the views relationship handler (relation_handler_relationship.inc) there is a join on the
entity_idwhich seems to be wrong. It should joinendpoints_entity_id.Patch attached.
Query without patch:
Query with patch:
Comment #2
marcusx commentedOk the first patch is bogus. The problem goes much deeper.
The views integration is badly broken. In joins the entity_id and endponints_entity_id are completely mixed up. This makes views in many cases completely unusable. Increasing priority therefore.
relation -> user is not working.
node -> relation -> user either.
The attached patch fixes it for my use cases but might not be a generic solution.
Comment #3
danylevskyiI can confirm that views relationships problem exists.
Patch #2 worked for me. At least next relations: 'relation → node' & 'relation → user' work like a charm.
Thanks for the patch!
Comment #4
Kazanir commentedI can confirm that the patch in #2 fixed me up. This seems pretty major; out of the box Views functionality (and fieldable reference entities) is the major reason Relation was useful to me.
Comment #5
mikran commentedWe definitely need tests for this.
Comment #6
marcusx commentedThe patch also needs work. I have found other combinations of relation settings where this is still broken.
I also don't like the condition in the if where I check if the field name is "rid" any ideas what we could check against instead are welcome.
I use this a lot and have some use cases I can use for testing. I can help improving the patch but I need to rethink all the stuff that is happening there maybe together with s.o. who has written the handler code in the first place. Happy holidays to all of you. And thanks for the work on relation.
Comment #7
mahmost commentedThe patch in #2 had a small problem in case of "entity -> relation" relationship when endpoints entity types are different , as it only joined on endpoints_entity_id without checking endpoints_entity_type .. so I made a small edit here .. still it seems not fully tested
Comment #8
danylevskyiHere is adopted patch of #7 for the last development release.
Comment #9
mikran commentedThe original issue claims that 'relation: number of rows' always returns 0. I've just tested this without any of the patches here on latest dev and I got the numbers I expected to get.
#1444800: Duplicate entries in view with node to node relationships got in recently and I think that has fixed this issue as well.