diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-18 15:14:39 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-18 15:14:39 -0700 |
commit | caf89fe3415982fd0b593ffcda9a58a083aa7e78 (patch) | |
tree | e9beb5d3a150d488c0d1e10492f65e1c44efb1ed | |
parent | 2a9117d8546941b90126d1548b0bbff85fca145a (diff) | |
download | rails-caf89fe3415982fd0b593ffcda9a58a083aa7e78.tar.gz rails-caf89fe3415982fd0b593ffcda9a58a083aa7e78.tar.bz2 rails-caf89fe3415982fd0b593ffcda9a58a083aa7e78.zip |
in fact, when doing subsequent orderings, we assume that the previous orderings have taken effect and therefore where the new ordering finds things equal, the previous ordering should take effect
-rw-r--r-- | lib/arel/relations/order.rb | 14 | ||||
-rw-r--r-- | spec/arel/unit/relations/order_spec.rb | 4 |
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/arel/relations/order.rb b/lib/arel/relations/order.rb index b1454973c8..662d3740df 100644 --- a/lib/arel/relations/order.rb +++ b/lib/arel/relations/order.rb @@ -1,15 +1,19 @@ module Arel class Order < Compound - attr_reader :orders - - def initialize(relation, *orders) - @relation, @orders = relation, orders.collect { |o| o.bind(relation) } + attr_reader :orderings + + def initialize(relation, *orderings) + @relation, @orderings = relation, orderings.collect { |o| o.bind(relation) } end def ==(other) self.class == other.class and relation == other.relation and - orders == other.orders + orderings == other.orderings + end + + def orders + orderings + relation.orders end end end
\ No newline at end of file diff --git a/spec/arel/unit/relations/order_spec.rb b/spec/arel/unit/relations/order_spec.rb index 514612f047..d373a8ba12 100644 --- a/spec/arel/unit/relations/order_spec.rb +++ b/spec/arel/unit/relations/order_spec.rb @@ -52,11 +52,11 @@ module Arel @another_attribute = @relation[:name] end - it "manufactures sql with the order clause of the last ordering" do + it "manufactures sql with the order clause of the last ordering preceding the first ordering" do Order.new(@ordered_relation, @another_attribute).to_sql.should be_like(" SELECT `users`.`id`, `users`.`name` FROM `users` - ORDER BY `users`.`name` + ORDER BY `users`.`name`, `users`.`id` ") end end |