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

marcusx’s picture

Status: Active » Needs review
StatusFileSize
new605 bytes

Same problem here.

I think this is a bug in the views relationship handler (relation_handler_relationship.inc) there is a join on the entity_id which seems to be wrong. It should join endpoints_entity_id.

Patch attached.

Query without patch:

SELECT node.title AS node_title, node.nid AS nid, relation_node.rid AS relation_node_rid, node.created AS node_created
FROM 
{node} node
INNER JOIN {field_data_endpoints} field_data_endpoints ON node.nid = field_data_endpoints.entity_id AND field_data_endpoints.bundle = 'eventregistration'
INNER JOIN {relation} relation_node ON field_data_endpoints.endpoints_entity_id = relation_node.rid AND field_data_endpoints.endpoints_entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN  ('event')) ))
ORDER BY node_created DESC

Query with patch:

SELECT node.title AS node_title, node.nid AS nid, relation_node.rid AS relation_node_rid, node.created AS node_created
FROM 
{node} node
INNER JOIN {field_data_endpoints} field_data_endpoints ON node.nid = field_data_endpoints.endpoints_entity_id AND field_data_endpoints.bundle = 'eventregistration'
INNER JOIN {relation} relation_node ON field_data_endpoints.endpoints_entity_id = relation_node.rid AND field_data_endpoints.endpoints_entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN  ('event')) ))
ORDER BY node_created DESC
marcusx’s picture

Priority: Normal » Major
StatusFileSize
new2.31 KB

Ok 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.

danylevskyi’s picture

I 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!

Kazanir’s picture

I 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.

mikran’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We definitely need tests for this.

marcusx’s picture

The 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.

mahmost’s picture

Title: node -> relation relationship not working » entity -> relation relationship not working
Status: Needs work » Needs review
StatusFileSize
new2.47 KB

The 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

danylevskyi’s picture

Here is adopted patch of #7 for the last development release.

mikran’s picture

Status: Needs review » Fixed

The 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.

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