From d9347943a22076911155d9a56d9a3ef6e022994b Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Tue, 19 Feb 2013 22:28:16 +0100 Subject: Windowing: Calling #rows or #range should assign framing only once. --- lib/arel/nodes/window.rb | 12 ++++++++++-- lib/arel/visitors/to_sql.rb | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/arel') 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 -- cgit v1.2.3