aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-08 20:35:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-08 20:35:28 -0700
commit3cbafe833b5c388403cd78c3bcb278850733d032 (patch)
treedf09ce41bd3c55a91610901ede08a1e9622e1c23 /lib/arel
parent9443c01b80f0942025634c9bd22cb741c891090c (diff)
downloadrails-3cbafe833b5c388403cd78c3bcb278850733d032.tar.gz
rails-3cbafe833b5c388403cd78c3bcb278850733d032.tar.bz2
rails-3cbafe833b5c388403cd78c3bcb278850733d032.zip
move all the "ORDER BY" together
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/visitors/mssql.rb16
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