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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spotzero’s picture

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

Thanks.

amitaibu’s picture

Status: Active » Needs review

Correct status for testbot to run.

amitaibu’s picture

+++ 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?

spotzero’s picture

Status: Needs review » Needs work

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

spotzero’s picture

Status: Needs work » Needs review
FileSize
5.47 KB

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().

amitaibu’s picture

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?

spotzero’s picture

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.

amitaibu’s picture

Status: Needs work » Needs review

Remember to set correct status for testbot :)

amitaibu’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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