aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMiguel Grazziotin <miguelgraz@gmail.com>2015-06-05 17:18:03 -0300
committerMiguel Grazziotin <miguelgraz@gmail.com>2015-06-05 17:18:03 -0300
commit2eb6b9dd0ba5049ee3a94f2f7ec7aa2fadd69dfc (patch)
treebb9e61043f89d41353ea7a575e722ea213581394 /activerecord
parent4e63a7b4b051aa8dc7ae53f46ea27cf421863561 (diff)
downloadrails-2eb6b9dd0ba5049ee3a94f2f7ec7aa2fadd69dfc.tar.gz
rails-2eb6b9dd0ba5049ee3a94f2f7ec7aa2fadd69dfc.tar.bz2
rails-2eb6b9dd0ba5049ee3a94f2f7ec7aa2fadd69dfc.zip
do not change the order of the result if the object was already ordered by the user via :order clause
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb1
-rw-r--r--activerecord/test/cases/finder_test.rb5
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 48a7d15ea8..a0e1420055 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -459,6 +459,7 @@ module ActiveRecord
end
if result.size == expected_size
+ return result if self.values[:order]
records_by_id = result.index_by(&:id)
ids.first(expected_size).collect { |id| records_by_id[id.to_i] }
else
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 3ea1299b1c..1ab91c5195 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -76,6 +76,11 @@ class FinderTest < ActiveRecord::TestCase
assert_equal 'The Third Topic of the day', records[0].title
assert_equal 'The First Topic', records[1].title
assert_equal 'The Fifth Topic of the day', records[2].title
+
+ records = Topic.order(:id).find([5,3,1])
+ assert_equal 'The First Topic', records[0].title
+ assert_equal 'The Third Topic of the day', records[1].title
+ assert_equal 'The Fifth Topic of the day', records[2].title
end
def test_find_with_ids_and_limit