[Bps-public-commit] r11304 - DBIx-SearchBuilder/trunk/SearchBuilder/Handle

ruz at bestpractical.com ruz at bestpractical.com
Mon Mar 31 17:07:03 EDT 2008


Author: ruz
Date: Mon Mar 31 17:07:03 2008
New Revision: 11304

Modified:
   DBIx-SearchBuilder/trunk/SearchBuilder/Handle/Pg.pm

Log:
* fix order by outer column in Pg

Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle/Pg.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle/Pg.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle/Pg.pm	Mon Mar 31 17:07:03 2008
@@ -230,7 +230,14 @@
         # If we are ordering by something not in 'main', we need to GROUP
         # BY and adjust the ORDER_BY accordingly
         local $sb->{group_by} = [@{$sb->{group_by} || []}, {FIELD => 'id'}];
-        local $sb->{order_by} = [map {($_->{ALIAS} and $_->{ALIAS} ne "main") ? {%{$_}, FIELD => "min(".$_->{FIELD}.")"}: $_} @{$sb->{order_by}}];
+        local $sb->{'order_by'} = [
+            map {
+                ($_->{'ALIAS'}||'') ne "main"
+                ? { %{$_}, FIELD => ((($_->{'ORDER'}||'') =~ /^des/i)?'MAX':'MIN') ."(".$_->{FIELD}.")" }
+                : $_
+            }
+            @{$sb->{'order_by'}}
+        ];
         my $group = $sb->_GroupClause;
         my $order = $sb->_OrderClause;
         $$statementref = "SELECT main.* FROM ( SELECT main.id FROM $$statementref $group $order ) distinctquery, $table main WHERE (main.id = distinctquery.id)";



More information about the Bps-public-commit mailing list