diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-10-29 16:30:08 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-10-29 16:30:08 +0100 |
commit | 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e (patch) | |
tree | a69ee3d1d8ba2770047f532aed9a1f778c36b08b /activerecord/test/cases | |
parent | ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34 (diff) | |
parent | 0fdc2dbe6f14221ccc3244eb749a72c9097e164c (diff) | |
download | rails-6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e.tar.gz rails-6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e.tar.bz2 rails-6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e.zip |
Merge pull request #22026 from akihiro17/fix-preload-association
Set `scope.reordering_value` to `true` if :reordering values aren't nil
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index bc1bff79d3..628ea1c764 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1179,6 +1179,24 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal 1, mary.unique_categorized_post_ids.length end + def test_preloading_has_one_using_reorder + klass = Class.new(ActiveRecord::Base) do + def self.name; "TempAuthor"; end + self.table_name = "authors" + has_one :post, class_name: "PostWithDefaultScope", foreign_key: :author_id + has_one :reorderd_post, -> { reorder(title: :desc) }, class_name: "PostWithDefaultScope", foreign_key: :author_id + end + + author = klass.first + # PRECONDITION: make sure ordering results in different results + assert_not_equal author.post, author.reorderd_post + + preloaded_reorderd_post = klass.preload(:reorderd_post).first.reorderd_post + + assert_equal author.reorderd_post, preloaded_reorderd_post + assert_equal posts(:sti_post_and_comments).title, preloaded_reorderd_post.title + end + def test_preloading_polymorphic_with_custom_foreign_type sponsor = sponsors(:moustache_club_sponsor_for_groucho) groucho = members(:groucho) |