aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-08-22 18:13:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-08-22 18:13:39 -0700
commita3b8ef8375056cd3b6a8cea49dec671f2a8f6c41 (patch)
tree0e9fd7645dcb8dc334ceabc91407a46910721095 /lib/arel
parent3283adc6d0edcc873256c78842f8ddd233577d08 (diff)
downloadrails-a3b8ef8375056cd3b6a8cea49dec671f2a8f6c41.tar.gz
rails-a3b8ef8375056cd3b6a8cea49dec671f2a8f6c41.tar.bz2
rails-a3b8ef8375056cd3b6a8cea49dec671f2a8f6c41.zip
orders are working
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes/select_statement.rb7
-rw-r--r--lib/arel/select_manager.rb5
-rw-r--r--lib/arel/visitors/to_sql.rb1
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