Browse files

Merge pull request #67 from ernie/pg_aliased_orders_fix

PostgreSQL aliased orders fix
  • Loading branch information...
2 parents 5214189 + b927452 commit a6d5f823a5d74c6884adfc88c30ad05624c4d674 @tenderlove tenderlove committed Jul 6, 2011
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/arel/visitors/postgresql.rb
  2. +8 −0 test/visitors/test_postgres.rb
View
2 lib/arel/visitors/postgresql.rb
@@ -42,7 +42,7 @@ def using_distinct_on?(o)
end
def aliased_orders orders
- #orders = o.orders.map { |x| visit x }.join(', ').split(',')
+ orders = orders.map { |x| visit x }.join(', ').split(',')
list = []
orders.each_with_index do |o,i|
list <<
View
8 test/visitors/test_postgres.rb
@@ -31,6 +31,14 @@ module Visitors
assert_match(/LIMIT 'omg'/, sql)
assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit'
end
+
+ it 'should alias Ordering nodes when using distinct on' do
+ sm = Arel::SelectManager.new Table.engine, Table.new(:blah)
+ sm.project 'DISTINCT ON (id) id'
+ sm.order(Nodes::Ordering.new(:id, :desc))
+ sql = @visitor.accept(sm.ast)
+ assert_match(/ORDER BY id_list.alias_0 DESC/, sql)
+ end
end
end
end

0 comments on commit a6d5f82

Please sign in to comment.