Working with Views2 I've found two places where I had to patch query.inc. Not a nice solution really. So, I've described both problems below and hope somebody will tell me that there is better way to handle them.
The first patch was related to the way query engine process aggregate fields. Presently it will check if field is supposed to be COUNT and if not, will add it to GROUP BY clause if present. Works fine except scenario when you want to use other aggregates such as MAX, MIN or SUM. In this case query engine will add those fields to GROUP BY clause as well, resulting in MySQL error. My solution was to add extra attribute to the field definition and analyze it in query(method)
if (isset($field['distinct'])) {
$string = "DISTINCT($string)";
}
if (isset($field['count'])) {
$string = "COUNT($string)";
$has_aggregate = TRUE;
}
// new code. we will check if field is aggregate and won't add it to non_aggregates array.
// this assumes that $field['aggregate'] property has been setup somewhere in field handler class
elseif (empty($field['aggregate'])) {
$non_aggregates[] = $fieldname;
}Can somebody come with alternative solution which does not require quiery.inc patch? If not, is it possible to somehow incorporate it into D6 code?
Second question is related to the way ensure_table() method works. For now it checks if table is present and already linked with base table ignoring the JOIN parameters. As a result when I add CCK userreference field relationship and want to see both node author and linked user, ensure table will find that in both cases node and users tables are in use and won't create second JOIN using different fields.
Again the question is am I doing something wrong or query.inc should be patched?
Comments
First, Views doesn't
First, Views doesn't currently support other aggregate functions. I don't have a solution for you at this time.
Second, if you add a table with non-standard joins then you should use an alias so that Views doesn't think it's the same join. That's one you can fix.