aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Staubo <alex@bengler.no>2013-02-19 22:28:16 +0100
committerAlexander Staubo <alex@bengler.no>2014-06-22 19:13:29 -0400
commitd9347943a22076911155d9a56d9a3ef6e022994b (patch)
tree0140b9e0b22204a12b5c6556d9d2b9f7c94c7414
parent69e9be95ac233eb7b446920bb49399277ea594ce (diff)
downloadrails-d9347943a22076911155d9a56d9a3ef6e022994b.tar.gz
rails-d9347943a22076911155d9a56d9a3ef6e022994b.tar.bz2
rails-d9347943a22076911155d9a56d9a3ef6e022994b.zip
Windowing: Calling #rows or #range should assign framing only once.
-rw-r--r--lib/arel/nodes/window.rb12
-rw-r--r--lib/arel/visitors/to_sql.rb2
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/arel/nodes/window.rb b/lib/arel/nodes/window.rb
index 6578a414d2..fee8eeff7a 100644
--- a/lib/arel/nodes/window.rb
+++ b/lib/arel/nodes/window.rb
@@ -30,11 +30,19 @@ module Arel
end
def rows(expr = nil)
- frame(Rows.new(expr))
+ if @framing
+ Rows.new(expr)
+ else
+ frame(Rows.new(expr))
+ end
end
def range(expr = nil)
- frame(Range.new(expr))
+ if @framing
+ Range.new(expr)
+ else
+ frame(Range.new(expr))
+ end
end
def initialize_copy other
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 8a5e1dbf25..8c63070084 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -343,11 +343,13 @@ module Arel
end
if o.orders.any?
+ collector << ' ' if o.partitions.any?
collector << "ORDER BY "
collector = inject_join o.orders, collector, ", "
end
if o.framing
+ collector << ' ' if o.partitions.any? or o.orders.any?
collector = visit o.framing, collector
end