[So far, I can't find any other posts on this problem. I _think_ the fix will ultimately have to be in the Views module, but I'm posting in both Views and Relation because it's relevant to both and I don't really know where to fix it.]
In views that contain relations, any node that doesn't have a value for a relation doesn't show up in the view at all, IF the account loading the view doesn't have the 'bypass content access control' permission. This happens even if 'require this relation' isn't checked. I have managed to trace the problem here:
SELECT
...
LEFT JOIN field_data_endpoints field_data_endpoints ON
node.nid = field_data_endpoints.endpoints_entity_id AND
(field_data_endpoints.bundle = 'provides' AND field_data_endpoints.endpo
ints_entity_type = 'node' AND field_data_endpoints.endpoints_r_index = '1')
LEFT JOIN field_data_endpoints field_data_endpoints2 ON
field_data_endpoints.entity_id = field_data_endpoints2.entity_id AND
(field_data_endpoints2.endpoints_entity_type = 'node' AND field_data_end
points2.endpoints_r_index != field_data_endpoints.endpoints_r_index AND 1 = '1'
)
LEFT JOIN node node_node ON
field_data_endpoints2.endpoints_entity_id = node_node.nid AND field_data
_endpoints2.endpoints_entity_type = 'node'
...
WHERE
...
( EXISTS (
SELECT na.nid AS nid
FROM node_access na
WHERE (
((na.gid = '0') AND (na.realm = 'all')) OR ((na.gid = '4
6') AND (na.realm = 'content_access_author')) OR ((na.gid = '2') AND (na.realm =
'content_access_rid')) OR
((na.gid = '4') AND (na.realm = 'content_access_rid'))
)
AND (na.grant_view >= '1') AND (node_node.nid = na.nid)
))
That EXISTS clause will fail if there are no permission rows for the other endpoint because the other endpoint is NULL. I have verified that replacing the EXISTS line with:
...
( node_node.nid IS NULL OR EXISTS (
...
produces the desired behavior (the row shows up, with blanks for the non-existent relations). What I haven't figured out is exactly where to even consider modifying the code to fix this. Most of the EXISTS clause is being generated in views/modules/node/views_handler_filter_node_access.inc, in views_handler_filter_node_access::query(), but I'm not sure about the EXISTS itself. Does anyone have any pointers to previous work on this, or where to patch the code?
Comments
Comment #1
naught101 commentedSorry, isn't very clear to me. You're saying that in a view of relations (as opposed to a view of content), any node that is not in a relation doesn't appear in the view? That sounds like what should happen, regardless of permissions.
That says "require this relationship", not relation. This may be me still not understanding what's happening, but you are aware that views relationships are totally unrelated to relation.module, right?
Can you please post some detailed steps to reproduce the problem, preferably using the git version, to make sure you've got all the latest bug fixes?
Comment #2
purplezephyr commentedSo here's an example. I have a widget content type, and two relation types, 'produced by' and 'distributed by', each of which has a vendor content type as the other endpoint. I create a view of widgets with both of those relations included as relationships under advanced->relationships, with 'position' specified as 'source'. Neither relationship is required (yes, misquoted before). I have content title included twice in the fields list, once with each relationship, so I can print the names of the companies that produce and distribute the widgets.
Now, if I have a widget that I have assigned both a producer and a distributer, it shows up in the view. But if I have a widget that only has a producer (say I don't know who's distributing it yet), it won't show up in the view, _unless_ I have admin privileges or the node->'bypass content access control' permission.
If I wanted this row not to show up, I could (and would) have specified that the relationship was required. I specifically DO want this row to show up, so I can see the data I actually have already and what's missing. And the permissions issue doesn't make sense as a feature (as opposed to a bug) because the row is missing even for accounts that have full access to all of the relevant content types and relations.
I get the same behavior with Relation 7.x-1.x-dev and Views 7.x-3.x-dev.
Comment #3
purplezephyr commentedP.S. https://drupal.org/node/2064447 is the issue I posted to the Views queue, for reference.
Comment #4
naught101 commentedOk, thanks for the detail, that helps. Unfortunately, I'm not seeing this problem. Unprivileged users can see rows with none, one or both relations.
Do you have any contextual filters? The only standard filter I have is "published (yes)". Page access settings are just "Access: Permission | View published content". All field settings are default (you don't have a rewrite on an empty field or something, do you?).
Comment #5
purplezephyr commentedIt turns out this is an interaction between Relation, Views, and Content Access, and there's a thread in Content Access. https://drupal.org/node/2020453. I'm going to post there, but any help you can still offer would be greatly appreciated.
Comment #6
naught101 commented#2020453: Views do not require relationship does not work if the relationship is not there makes it sound like purely a views/content access problem. Let's close this as a duplicate. Reopen if that issue is solved and you still have a problem.
Comment #7
purplezephyr commentedThe answer turns out to be this patch (#174) for core:
https://drupal.org/comment/8363849#comment-8363849
h/t vramirez1 in https://drupal.org/comment/8400091#comment-8400091