diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 20:35:28 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 20:35:28 -0700 |
commit | 3cbafe833b5c388403cd78c3bcb278850733d032 (patch) | |
tree | df09ce41bd3c55a91610901ede08a1e9622e1c23 /lib/arel/visitors | |
parent | 9443c01b80f0942025634c9bd22cb741c891090c (diff) | |
download | rails-3cbafe833b5c388403cd78c3bcb278850733d032.tar.gz rails-3cbafe833b5c388403cd78c3bcb278850733d032.tar.bz2 rails-3cbafe833b5c388403cd78c3bcb278850733d032.zip |
move all the "ORDER BY" together
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/mssql.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/arel/visitors/mssql.rb b/lib/arel/visitors/mssql.rb index 49f79c527d..479a867e37 100644 --- a/lib/arel/visitors/mssql.rb +++ b/lib/arel/visitors/mssql.rb @@ -27,11 +27,9 @@ module Arel return super o end - select_order_by = "ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty? - is_select_count = false sql = o.cores.map { |x| - core_order_by = select_order_by || determine_order_by(x) + core_order_by = determine_order_by(o.orders, x) if select_count? x x.projections = [row_num_literal(core_order_by)] is_select_count = true @@ -58,11 +56,15 @@ module Arel end end - def determine_order_by x - if x.groups.any? - "ORDER BY #{x.groups.map { |g| visit g }.join ', ' }" + def determine_order_by orders, x + if orders.any? + "ORDER BY #{orders.map { |x| visit x }.join(', ')}" else - "ORDER BY #{find_left_table_pk(x.froms)}" + if x.groups.any? + "ORDER BY #{x.groups.map { |g| visit g }.join ', ' }" + else + "ORDER BY #{find_left_table_pk(x.froms)}" + end end end |