Skip to content

Commit

Permalink
Fix Visitors::PostgreSQL#aliased_orders to handle Ordering nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernie Miller committed Jul 6, 2011
1 parent 5214189 commit b927452
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/arel/visitors/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<
Expand Down
8 changes: 8 additions & 0 deletions test/visitors/test_postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 b927452

Please sign in to comment.