Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#3 | member_count_relationship.patch | 1.23 KB | lefnire |
#2 | member_count_relationship.patch | 1.25 KB | lefnire |
Comments
Comment #1
gokulnk CreditAttribution: gokulnk commentedFaced 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
where node_node_data_field_groupnode1_groupnode2_reference_nid is the reference field based on which the relationship is built.
Comment #2
lefnire CreditAttribution: lefnire commentedI 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.
Comment #3
lefnire CreditAttribution: lefnire commentedI guess no need to call add_additional_fields() in the end
Comment #4
Grayside CreditAttribution: Grayside commentedHey 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