This is essentially the reverse of the bug fixed in http://drupal.org/node/1904622.

If you're using multiple entity types as groups, the "@entity from OG membership" and "Group @entity from OG membership" views relationships will return errorious data.

For "@entity from OG membership", the view query is:

SELECT ...
FROM
{og_membership} og_membership
LEFT JOIN groupentity ON og_membership.gid = groupentity.id

but needs to be:

SELECT ...
FROM
{og_membership} og_membership
LEFT JOIN groupentity ON og_membership.gid = groupentity.id AND og_membership.entity_type = 'groupentity'

And for "Group @entity from OG membership", the view query is:

SELECT ...
FROM
{og_membership} og_membership
LEFT JOIN groupentity ON og_membership.gid = groupentity.id

but needs to be:

SELECT ...
FROM
{og_membership} og_membership
LEFT JOIN groupentity ON og_membership.gid = groupentity.id AND og_membership.group_type = 'groupentity'

Thanks

Files: 
CommentFileSizeAuthor
#7 og-view-relationship-from-og-membership-join-filtering-1905802-7.patch5.51 KBspotzero
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]
#5 og-view-relationship-from-og-membership-join-filtering-1905802-5.patch5.47 KBspotzero
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]
#1 og-view-relationship-from-og-membership-join-filtering-1905802-1.patch3.61 KBspotzero
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

Comments

StatusFileSize
new3.61 KB
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

The attached patch adds the required relationship handlers to handle these cases.

Thanks.

Status:Active» Needs review

Correct status for testbot to run.

+++ b/includes/views/handlers/og_handler_relationship_related.incundefined
@@ -0,0 +1,27 @@
+      'field' => 'entity_type',

We probably don't need 2 handlers for this -- can't we have only a single one, that changes the field according to some property we pass in the data array?

Status:Needs review» Needs work

Definitely. Just let me write it and I'll roll you a patch.

Status:Needs work» Needs review
StatusFileSize
new5.47 KB
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

I've reduced all of the views relationship handlers into one more intelligent handler.

This relationship handler handles the og_membership table being in either the right or left positions of the join, as well as including options for filtering the join by the group_type, entity_type, or both.

Its behaviour is definited by the relationship definition in og_views_data_alter().

Status:Needs review» Needs work

Getting very close :) Nit picks:

+++ b/includes/views/handlers/og_handler_relationship.incundefined
@@ -17,12 +17,42 @@ class og_handler_relationship extends views_handler_relationship {
+    //  filter the join to select membership of those entity types

Extra space.
End line with dot.

+++ b/includes/views/handlers/og_handler_relationship.incundefined
@@ -17,12 +17,42 @@ class og_handler_relationship extends views_handler_relationship {
+      // Only add the table if og_membership is the left table since when the table is specified to views_join,

Comments should be up to the 80 chars margin, per line.

+++ b/includes/views/handlers/og_handler_relationship.incundefined
@@ -17,12 +17,42 @@ class og_handler_relationship extends views_handler_relationship {
+    //   filter the join to select membership of those group types

Extra space

+++ b/includes/views/handlers/og_handler_relationship.incundefined
@@ -17,12 +17,42 @@ class og_handler_relationship extends views_handler_relationship {
+    if (isset($this->definition['group_type'])) {

Shouldn't be elseif?

StatusFileSize
new5.51 KB
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

The attached patchfixed the various issues, except for the last one.

The second 'if' is not an 'elseif' so that this relationship handler has the option of filtering joins by both entity_type and group_type.

Honestly, I don't have a use-case for this behaviour, but it's valid, so there could be one. This may be functionality that will never be used, but it shouldn't break anything.

Status:Needs work» Needs review

Remember to set correct status for testbot :)

Status:Needs review» Fixed

Committed, thanks.

Status:Fixed» Closed (fixed)

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