From 64b8765c22222821911f0018e30b03f80112a1f1 Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Sat, 6 Nov 2010 19:11:23 +0200 Subject: fix order_hacks method for Oracle when complex functions are used in order by --- lib/arel/visitors/oracle.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index 212c18ada4..bb6ebd4ab8 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -70,7 +70,23 @@ module Arel /DISTINCT.*FIRST_VALUE/ === projection end end - orders = o.orders.map { |x| visit x }.join(', ').split(',') + # FIXME: previous version with join and split broke ORDER BY clause + # if it contained functions with several arguments (separated by ','). + # Currently splitting is done only if there is no function calls + # + # orders = o.orders.map { |x| visit x }.join(', ').split(',') + orders = o.orders.map do |x| + string = visit x + # if there is function call + if string.include?('(') + string + # if no function call then comma splits several ORDER BY columns + elsif string.include?(',') + string.split(',') + else + string + end + end.flatten o.orders = [] orders.each_with_index do |order, i| o.orders << -- cgit v1.2.3