0

I have a view which filters all the organic groups for a user. I wanted to add a Views Filter to filter by OG Role, however it is not possible.

I would very much appreciate any help. Basically any OG Role filter using a Views Filter Handler cannot be used if the database is an MSSQL database. When selecting one of the filters, it errors out and then the view has to be re-created since the view can no longer be shown within the UI. I opened a drupal issue a few months ago, but no response as of yet.

The error message is as follows:

PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Column 'og_role.rid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.: SELECT r.*, r.name AS _field_0 FROM {og_role} r GROUP BY r.name; Array ( ) in og_handler_filter_user_roles->get_value_options() (line 14 of C:\inetpub\wwwroot\sites\all\modules\og\includes\views\handlers\og_handler_filter_user_roles.inc).

I'm almost postive that I have to rewrite Line 13 to support SQLSRV database types.

Line 13: ->groupBy('r.name')

Here is the relevant code:

/**
 * Field handler to provide a list of OG roles of a user.
 */
class og_handler_filter_user_roles extends views_handler_filter_many_to_one {

  function get_value_options() {
    $this->value_options = array();
    // Get all role names.
    $results = db_select('og_role', 'r')
      ->fields('r')
      ->groupBy('r.name')
      ->execute();
    foreach ($results as $result) {
      $this->value_options[$result->name] = $result->name;
    }
  }

  function query() {
    // Get the og_membership table from relations.
    foreach ($this->query->relationships as $alias => $info) {
      if ($info['table'] == 'og_membership') {
        // If there is a og_membership table present. Add some conditions.
        $rel = $this->relationship;
        $this->query->add_where_expression(NULL, $alias . '.gid = ' . $rel . '.gid');
        $this->query->add_where_expression(NULL, $alias . '.group_type = ' . $rel . '.group_type');
        break;
      }
    }

    parent::query();
  }
}
8
  • 1
    This question appears to be off-topic because it is a bug report for a module, and should be reported in module's issue queue. Reporting bugs here is forbidden, see help center. – Mołot Dec 17 '13 at 12:44
  • Ok then please close the help request. I only submitted it, because I felt it was a way to also learn how to patch issues such as this for the future, but if it doesn't belong, then it no longer needs to remain open. Thanks for the prompt response. – NWOM Dec 17 '13 at 12:46
  • if you want to learn how to patch etc, it might be OK, but, also in help center, there is a requirement to provide relevant parts of code if you are asking how to fix code. If you identified the place that causes this error, you may edit relevant part into your question, then tell us what have you tried to make it work, and expect us to answer :) That you are welcome to do, all right. – Mołot Dec 17 '13 at 12:49
  • Close vote retracted, and edited it a bit to improve formatting. Good luck. Have you tried adding ->groupBy('r.rid') just after ->groupBy('r.name')? – Mołot Dec 17 '13 at 12:59
  • Amazing. Thank you very much. As soon as I added that, it shows that another one was missing, and then another, etc. etc. Line 13 is now: ->groupBy('r.name')->groupBy('r.rid')->groupBy('r.gid')->groupBy('r.group_type')->groupBy('r.group_bundle'). Thank you very much. Would you like to add the answer, or should I? – NWOM Dec 17 '13 at 13:05
1

I fixed it by changing Line 13 to:

->groupBy('r.name')
->groupBy('r.rid')
->groupBy('r.gid')
->groupBy('r.group_type')
->groupBy('r.group_bundle')
1
  • Please try to use code syntax for code. And no need for a "thank you" in answers :) if you really feel you need, put it in comment (just don't get surprised when it's get deleted) – Mołot Dec 17 '13 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.