Hello,
let me try to explain my simple relation setup:
Node A {relation} Node B {other_relation} Node C
Node A has a {relation} to Node_B and Node B has an {other_relation} to Node C.
Both relations are optional and I'm not going to require them.
When displaying Node A, I'm going to display fields from Node B and Node C. I'm going to display those fields only if the relationship exists, if they don't exist, the fields are not shown. This is no problem using views.
The Problem:
If I don't require the relationships I get duplicate entries like:
- Node A itself
- Node A with fields from Node B
- Node A with fields from Node B and fields from Node C
The common solution would be to require the relationships but as I also need to display nodes that have no relationships to other nodes I can't go with that. What can I do now to remove the duplicate values?
That means if a relationship form A to B exists, just A alone (1.) without data from B should be no longer displayed.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | relation-optional-views-relations-1444800-10.patch | 18.19 KB | jorrit |
| #7 | relation-optional-views-relations-1444800-7.patch | 5.61 KB | jorrit |
Comments
Comment #1
hevr commentedDatabase-wise I could think of some ORDER BY and GROUP BY action but this don't seem really feasible because this would need a subquery for ORDERing before GROUPing the subquery.
Comment #2
mikran commentedIssue #1506524: Duplicate entries in view with node->node relation was duplicate to this. I also tested this and noticed that with just one relation the duplication won't occur.
Comment #3
osopolarOn #1506524: Duplicate entries in view with node->node relation I pointed out the important differences between the two sql queries one using the views relationship node->node and the other using two relationships 1:node->relation and 2:relation->node (which is somehow also a node-to-node relationship). Using the first two relationships, I set Position of the relationship base for the first to source and for second to target. For the node->node I only can set source, there is no second option to set the joined node to target. I guess this results in the difference between the two ways to get a node-to-node relationship, one with and the other one without duplicates.
Comment #4
osopolarComment #5
timb commentedI ran into this issue of duplicates appearing in views on a site with one node=>node relation. I did as was suggested in number #3 and was able to remedy this, but it does make the setup less intuitive. I do not think this was an issue until the last update of relation.
Comment #6
marcoka commentedi am having the same issue. "require relationship fixes" it but then you are not able to see what node has NO relationship (for example to check who forgot to add one).
Comment #7
jorrit commentedI think the query that results when an optional node -> node relation is used is wrong:
I think it should be:
Attached patch achieves this. It also adds a left/right text to the "Avoid left node duplication" checkbox, although I don't really get its function.
I am interested to hear if it also solves your problems.
Comment #8
jorrit commentedComment #10
jorrit commentedIn my opinion, the test was expecting erroneous output. In the case that failed, there was a symmetric relation between two entities (A and B). For a non-required relationship, the expected result was two rows, one with (A, B) and one with (A, NULL). I think this behavior is unwanted: the choice between required and non-required should only affect the inclusion of entities that do not have a relationship of that kind. I have improved the tests by also including tests for a node without any relations (node6). I have split the large test method in relation.views.test so debugging test failures becomes easier.
Comment #11
mikran commentedAwesome, thanks for patch.
Comment #12
jorrit commentedThanks for the commit and git attribution.