At some point (rc2 upgrade?) the group by stopped working on my view. The sql generated has a group-by node_vid that essentially negates any grouping. I'm not sure what changed or how to get around this.
Here's the sql generated:
SELECT COUNT(node.nid) AS nid, node.type AS node_type, node_data_field_progtype.field_progtype_value AS node_data_field_progtype_field_progtype_value, node.vid AS node_vid FROM node node LEFT JOIN content_type_program node_data_field_progtype ON node.vid = node_data_field_progtype.vid WHERE (node.type in ('program')) AND (node.status <> 0) GROUP BY node_data_field_progtype_field_progtype_value, node_type, node_vid ORDER BY node_data_field_progtype_field_progtype_value DESC
If I remove by hand the group-by node_vid... the query works.
Settings:
Fields to Group On = field_progtype
Sql Aggregation Function = count
Fields to Aggregate with the SQL Function = Node: NID
Field to Sort Resultset On: field_progtype
Example:
Tho limited to displaying one row, the "Funded Program Summary Statistics" section would like to display all 67... and not group by.
http://intc.education.illinois.edu/programs
Comment | File | Size | Author |
---|---|---|---|
#6 | views_groupby-651546-6.patch | 979 bytes | glennpratt |
Comments
Comment #1
knystrom CreditAttribution: knystrom commentedWe rolled back to rc1 and the issue disappeared. We see that 4 lines of code were commented out between the versions, tho we don't see documentation as to why.
Here's the sql generated by rc1:
SELECT COUNT(node.nid) AS nid, node_data_field_progtype.field_progtype_value AS node_data_field_progtype_field_progtype_value FROM node node LEFT JOIN content_type_program node_data_field_progtype ON node.vid = node_data_field_progtype.vid WHERE (node.type in ('program')) AND (node.status <> 0) GROUP BY node_data_field_progtype_field_progtype_value ORDER BY node_data_field_progtype_field_progtype_value DESC
Comment #2
johnbarclay CreditAttribution: johnbarclay commentedI don't fully understand the function query() in views_groupby_handler_field_groupfields.inc; but changing:
to:
seems to deal with the vid problem. Perhaps when the $bfield line was commented out, too the unset line was commented out by accident.
Comment #3
neffets CreditAttribution: neffets commentedI think the problem is the new VIEWS version (6.x-2.8)
in views/includes/query.inc line 977
$groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n";
it adds an "non_aggregate" array to the group by fields, so there were added nid and vid too
To the non_aggregate array are in this query-function added all fields, that have not attribute
$field['count'] or attribute $field['aggregate']
A pathc with a aggregate attribute for all fields ($this->query->fields[fields]->aggregate='no') would break the views patch for ANSI SQL compliance (e.g. with postgres) see http://drupal.org/node/385158#comment-1296924
But we can trick it if all results would be distinct, then a patch would do like:
--- views_groupby/handlers/views_groupby_handler_field_groupfields.inc.ORIG 2009-12-11 03:14:10.000000000 +0100
+++ views_groupby/handlers/views_groupby_handler_field_groupfields.inc 2009-12-11 06:27:53.000000000 +0100
@@ -261,6 +261,10 @@
$sz_to_group .= $field;
}
$this->query->add_groupby($sz_to_group);
+ if ($count) { // issue #385158: query->add_groupby & aggregate vs. nonaggregate fields und issue #651546: Group By not working due to vid
+ $this->query->distinct=TRUE;
+ $this->query->no_distinct='views_groupby'; //prevent views-behaviour to add nid(base_field) allways
+ }
}
$views_fields = $this->_get_views_fields($just_aliases=TRUE);
Comment #4
stefanhapper CreditAttribution: stefanhapper commentedRe comment #3 -> we are facing the same problem, but with Views 2.6 (not 2.8)
We tried with Views Group By dev versions of 6 November and 22 November 2009
Was anyone able to solve this problem? For us it makes Views Group By completely unusable for the moment.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedSame problem, group by node_vid renders grouping obsolete. Using rc2 and views 6.x-2.7.
Reverted back to rc1 and it worked again...
Comment #6
glennpratt CreditAttribution: glennpratt commented#3 works for me. Here's a patch, credit to neffets.
Comment #7
mattiasj CreditAttribution: mattiasj commentedSame problem here with RC2 and Views 2.8. Will try this patch out!
Comment #8
mineshaftgap CreditAttribution: mineshaftgap commentedI think the patch in #6 is a MySQL only solution, as it breaks on Postgres.
Comment #9
glennpratt CreditAttribution: glennpratt commentedmineshaftgap: Could your issue be related to this Views issue? #506818: [Postgres] GROUP BY uses field names instead of aliases
Comment #10
mineshaftgap CreditAttribution: mineshaftgap commentedGlenn,
I think that you are correct. Thanks for the input, unfortunately it seems like it is still an open issue, so for now I will be using hook_views_query_alter/hook_views_pre_render/etc or jumping out of Views for my needs.
Comment #11
glennpratt CreditAttribution: glennpratt commentedChanging to needs review, hoping to get more eyes on this.
Comment #12
cpall CreditAttribution: cpall commentedPatched worked beautifully for me. (mySQL)
Comment #13
denney CreditAttribution: denney commentedPatch worked perfect for me to.
Comment #14
TravisCarden CreditAttribution: TravisCarden commented#6 works for me, too. (MySQL 5.0)
Comment #15
darrick CreditAttribution: darrick commentedThis patch worked well for me. However, I also had some trouble with having a date field set in the sort field which was populating the groupby array.
Comment #16
alexharries CreditAttribution: alexharries commentedThank you Glenn - that worked perfectly for me too =o)
Comment #17
nottaken CreditAttribution: nottaken commented#6 worked for me. I was banging my head trying to figure this out for a few hours. Thanks.
Comment #18
skylord CreditAttribution: skylord commented#6 works for me too. Please, make release with it!
Comment #19
arithmetric CreditAttribution: arithmetric commentedThis patch is working for me too. Marking it as RTBC.
Comment #21
Liutauras CreditAttribution: Liutauras commented#6 patch works for me too. Please, make release with it!
Comment #22
arithmetric CreditAttribution: arithmetric commentedThis patch was committed with this change: http://drupal.org/cvs?commit=484634
It's now part of the dev release (6.x-1.x).