diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-06-25 19:34:51 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-26 00:59:12 +0200 |
commit | 65aa6a7db16b7387d5a3bf1ad7f5a602804a2f21 (patch) | |
tree | a66aa73a99c67b4828e861a176e5fd7d6b00158f /activerecord/lib | |
parent | a2513aea07255877b66b846fcf7ebb35629199df (diff) | |
download | rails-65aa6a7db16b7387d5a3bf1ad7f5a602804a2f21.tar.gz rails-65aa6a7db16b7387d5a3bf1ad7f5a602804a2f21.tar.bz2 rails-65aa6a7db16b7387d5a3bf1ad7f5a602804a2f21.zip |
reorder method added to ActiveRelation
[#4972 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 4dbb30c777..f7c4c7991b 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -21,6 +21,14 @@ module ActiveRecord CEVAL end + def reorder(*args, &block) + new_relation = clone + new_relation.send(:apply_modules, Module.new(&block)) if block_given? + value = Array.wrap(args.flatten).reject {|x| x.blank? } + new_relation.order_values = value if value.present? + new_relation + end + def select(*args) if block_given? to_a.select { |*block_args| yield(*block_args) } |