From 66fc8add90445289f4926a914b0eea0c1989450f Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Thu, 23 Sep 2010 13:37:03 -0700
Subject: writing code that makes me sad

---
 lib/arel/visitors/postgresql.rb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'lib/arel/visitors')

diff --git a/lib/arel/visitors/postgresql.rb b/lib/arel/visitors/postgresql.rb
index 5f0b23a11e..e8aa9b8cb3 100644
--- a/lib/arel/visitors/postgresql.rb
+++ b/lib/arel/visitors/postgresql.rb
@@ -12,7 +12,7 @@ module Arel
           sql = super(subquery)
           [
             "SELECT * FROM (#{sql}) AS id_list",
-            "ORDER BY #{o.orders.map { |x| visit x }.join(', ')}",
+            "ORDER BY #{aliased_orders(o.orders).join(', ')}",
             ("LIMIT #{o.limit}" if o.limit),
             (visit(o.offset) if o.offset),
           ].compact.join ' '
@@ -28,6 +28,11 @@ module Arel
           end
         end
       end
+
+      def aliased_orders orders
+        #orders = o.orders.map { |x| visit x }.join(', ').split(',')
+        (0...orders.size).map { |i| "id_list.alias_#{i}" }
+      end
     end
   end
 end
-- 
cgit v1.2.3