Got a view that shows all Organic Groups related to the current Organic Group. The relationship is based on a node-reference field, and the current OG is from the URL argument.

All fields use the relationship, and they all show up fine except Member Count, which doesn't use the relationship in the query even though it's setup to do so in Views UI. The field query looks something like:

SELECT node.nid as nid,
node_node_data_field_community_reference.title AS node_node_data_field_community_reference_title,
(SELECT COUNT(*) FROM og_uid ou INNER JOIN users u ON ou.uid = u.uid WHERE ou.nid = og.nid AND u.status > 0 AND ou.is_active >= 1 AND ou.is_admin >= 0 ) AS member_count,
...

I can post an exported view if needs be

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gokulnk’s picture

Faced a similar situation in one of our projects. This is how we solved it.

Install custom-field module and a php customfield. And then add this code to

<?php
  $node = node_load($data->node_node_data_field_groupnode1_groupnode2_reference_nid);
  list($txt, $subscription) = og_subscriber_count_link($node);
  print($txt);
?>

where node_node_data_field_groupnode1_groupnode2_reference_nid is the reference field based on which the relationship is built.

lefnire’s picture

I think just pulling from $this->aliases instead of the hard-coded 'og.nid' would do the trick. Uploading a patch, it works but it was a shot in the dark so make sure it's sensical.

lefnire’s picture

I guess no need to call add_additional_fields() in the end

Grayside’s picture

Status: Active » Fixed

Hey there lefnire! Remember to patch with --relative from the OG project root, and set issues with patches to Needs Review or Needs Work accordingly :)

http://drupalcode.org/project/og.git/commit/4348c80

Status: Fixed » Closed (fixed)

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