diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index ae10a551e3da7aafd51391b126fc484e8567587d..efc72f43c1a8bd6b8e8f1d70b841f0c9cf48e9cf 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -405,6 +405,7 @@ def reorder(*args) # Same as #reorder but operates on relation in-place instead of copying. def reorder!(*args) # :nodoc: preprocess_order_args(args) unless args.all?(&:blank?) + args.uniq! self.reordering_value = true self.order_values = args self diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 2719a5b3bb1218a43e27a8c7fcfa357da6300e88..b005b6ac2077a076646c1d58bda2707432473fdb 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -425,6 +425,11 @@ def test_finding_with_reorder assert_equal ["The First Topic", "The Second Topic of the day", "The Third Topic of the day", "The Fourth Topic of the day", "The Fifth Topic of the day"], topics_titles end + def test_reorder_deduplication + topics = Topic.reorder("id desc", "id desc") + assert_equal ["id desc"], topics.order_values + end + def test_finding_with_reorder_by_aliased_attributes topics = Topic.order("author_name").reorder(:heading) assert_equal 5, topics.to_a.size