diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/nodes/select_statement.rb | 7 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 5 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 |
3 files changed, 10 insertions, 3 deletions
diff --git a/lib/arel/nodes/select_statement.rb b/lib/arel/nodes/select_statement.rb index 50fef776f6..d00a079dc3 100644 --- a/lib/arel/nodes/select_statement.rb +++ b/lib/arel/nodes/select_statement.rb @@ -2,11 +2,12 @@ module Arel module Nodes class SelectStatement attr_reader :cores - attr_accessor :limit + attr_accessor :limit, :orders def initialize cores = [SelectCore.new] - @cores = cores - @limit = nil + @cores = cores + @orders = [] + @limit = nil end def initialize_copy other diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 462b0765a5..3d6aef0745 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -28,6 +28,11 @@ module Arel self end + def order *expr + @head.orders.concat expr + self + end + def wheres Compatibility::Wheres.new @engine, @ctx.wheres end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 401bdb3255..55ed53177e 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -45,6 +45,7 @@ module Arel def visit_Arel_Nodes_SelectStatement o [ o.cores.map { |x| visit x }.join, + ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), ("LIMIT #{o.limit}" if o.limit) ].compact.join ' ' end |