Comments

webankit’s picture

Status: Active » Needs review
StatusFileSize
new574 bytes
steveoliver’s picture

@webankit: 'entity_type_right' => $entity_type_left just seems all wrong, don't ya think?

webankit’s picture

The logic which I predicted and made this change was:
'entity_type_left' for the join should be relation (as we are using it as the base table)
and
'entity_type_right' for the join should be entity we are trying to join (i.e $entity_type_left).
I tried and it's working:)

mikran’s picture

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

A test to show this error (and the fix) would be really nice. I can believe you that it's working but it's likely to get broken again

hlykos’s picture

Patch seems to work.

Example query wihout the patch:

SELECT relation.created AS relation_created, node_relation.title AS node_relation_title, node_relation.nid AS node_relation_nid
FROM 
relation relation
LEFT JOIN field_data_endpoints field_data_endpoints ON relation.rid = field_data_endpoints.endpoints_entity_id AND (field_data_endpoints.bundle = 'reserved_by' AND field_data_endpoints.endpoints_entity_type = 'node' AND field_data_endpoints.endpoints_r_index = '0')
LEFT JOIN node node_relation ON field_data_endpoints.entity_id = node_relation.nid
WHERE (( (relation.relation_type IN  ('reserved_by')) ))
LIMIT 10 OFFSET 0

Example query with the patch:

SELECT relation.created AS relation_created, node_relation.title AS node_relation_title, node_relation.nid AS node_relation_nid
FROM 
relation relation
LEFT JOIN field_data_endpoints field_data_endpoints ON relation.rid = field_data_endpoints.entity_id AND (field_data_endpoints.bundle = 'reserved_by' AND field_data_endpoints.endpoints_r_index = '0')
LEFT JOIN node node_relation ON field_data_endpoints.endpoints_entity_id = node_relation.nid AND field_data_endpoints.endpoints_entity_type = 'node'
WHERE (( (relation.relation_type IN  ('reserved_by')) ))
LIMIT 10 OFFSET 0
alan evans’s picture

FWIW I also have a prototype site which was broken and is fixed by this patch. (and confirm similar query changes to hlykos)

Agreed that a test would be good, and potentially might be worth some comment and maybe some variable renaming (even if just copying the _left variable into something named better for this case).

gaëlg’s picture

StatusFileSize
new7.73 KB

Here's a renaming patch (with no logic changes, so that previous patch is not included). It should be easier to debug with right names. Left has been replaced with source, and right with target, so that we don't get confused with left and right joins SQL considerations.
And it looks like the previous patch just partially solve the bug, the SQL of my view still have some errors. I'm working on this.

gaëlg’s picture

My bad, the previous patch works. I had another not related problem.

steveoliver’s picture

GaëlG: Think you could roll a git patch for this?

gaëlg’s picture

Status: Needs work » Needs review
StatusFileSize
new10.62 KB

Here's a merge of #1 and #7.

mikran’s picture

Status: Needs review » Needs work

Tests.

Maybe, exported view that is as small as possible in order to reproduce this bug and then we create a test from that. We're generally very light on test coverage for views support and that would be nice to fix before the stable release.

jhoffmcd’s picture

#10 confirmed for me, I was dealing with this for I while before I happened upon this thread. Thanks all.

bsarchive’s picture

#10 isn't working for me. Plus I have a few additional configurations that don't function, as follows:

I've got a directional relation: user->node

In a view of users (source):
- views relationship from user to node (source to target) works
- views relationship from user to relation (source to relation) works

In a view of nodes (target)
- views relationship from node to user (target to source) works
- views relationship from node to relation (target to relation) doesn't work

In a view of relations
- views relationship from relation to node (relation to target) works
- views relationship from relation to user (relation to source) doesn't work

?? This is breaking me this issue - hope someone can help!

Plus, this patch breaks all views relationships to relations. Is it possible to create a patch that upgrades gracefully?

bsarchive’s picture

Issue summary: View changes
Priority: Normal » Major
Status: Needs work » Needs review

I think I've worked this out now:
the patch in #1 to /relation/views/relation.views.inc changed line 334
from

'entity_type_left' => $entity_type_left,
to
'entity_type_right' => $entity_type_left,
which fixed views relationship: relation->source

in the same file, changing line 319
from
'entity_type_right' => $entity_type_right,
to
'entity_type_left' => $entity_type_right,
fixes views relationship: target->relation

I don't know how to write patches correctly so if someone could add this to patch #1, that would be great!

I've tested all views relationships (src->tar, tar->src, src->rel, rel->src, tar->rel, rel->tar) with two cases (1: same entity types in src and tar; 2; different entity types) and all seem work fine.

Can we get this committed? Seems to me now that the main thing distinguishing Relation module from Entityreference (now in D8 core) is that relations are fieldable. To access the fields in views you need the relationships to the relations so this issue is critical to the usefulness of the Relation module. This is why I've upgraded this issue to 'major'.

bsarchive’s picture

Patches #7 and #10 (which change the names of the variables and array keys) will break any views which have a views relationship from relation->source.

I'd suggest keeping the names the same. The necessary change in the code is just two words.

marcusx’s picture

Can confirm that we need to add the changes in #14 to get this working for target -> relation.

Added this change to a new patch version.

What about the name change? Should we go with left / right or source / target. Any opinions about that? Should we split this into two separate issues? Would make sense I think.

Paul B’s picture

Here's a patch that just makes the two changes in #14.
I think the renaming should be a separate issue.

mikran’s picture

Views tests added for "relation → endpoint" and "endpoint → relation" views. And yes, we shouldn't break existing views so patch #17 is better.

The last submitted patch, 18: relation_views_relationship_fix_tests_only-1780424-18.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: relation_views_relationship_fix-1780424-18.patch, failed testing.

The last submitted patch, 18: relation_views_relationship_fix_tests_only-1780424-18.patch, failed testing.

The last submitted patch, 18: relation_views_relationship_fix-1780424-18.patch, failed testing.

mikran’s picture

Status: Needs work » Needs review
StatusFileSize
new5.4 KB
new6.42 KB

Oh, wrong views field name.

The last submitted patch, 23: relation_views_relationship_fix_tests_only-1780424-23.patch, failed testing.

mikran’s picture

Status: Needs review » Fixed

This one is now committed as well.

Status: Fixed » Closed (fixed)

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