aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md22
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb3
-rw-r--r--activerecord/test/cases/associations/eager_test.rb6
3 files changed, 1 insertions, 30 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index d28709affb..b0e0d56990 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,27 +1,5 @@
## unreleased ##
-* Preloading `has_many :through` associations with conditions won't
- cache the `:through` association. This will prevent invalid
- subsets to be cached.
- Fixes #8423.
-
- Example:
-
- class User
- has_many :posts
- has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
- end
-
- a_user = User.includes(:recent_comments).first
-
- # this is preloaded
- a_user.recent_comments
-
- # fetching the recent_comments through the posts association won't preload it.
- a_user.posts
-
- *Yves Senn*
-
* Fix counter cache columns not updated when replacing `has_many :through`
associations.
Backport #8400.
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index 0f1336bd00..ad6374d09a 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -37,8 +37,7 @@ module ActiveRecord
through_records = Array.wrap(owner.send(through_reflection.name))
# Dont cache the association - we would only be caching a subset
- if (through_scope != through_reflection.klass.unscoped) ||
- (reflection.options[:source_type] && through_reflection.collection?)
+ if reflection.options[:source_type] && through_reflection.collection?
owner.association(through_reflection.name).reset
end
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 5d07ffa241..20c6b691fc 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1112,10 +1112,4 @@ class EagerAssociationTest < ActiveRecord::TestCase
Post.includes(:comments).order(nil).where(:comments => {:body => "Thank you for the welcome"}).first
end
end
-
- test "preloading does not cache has many association subset when preloaded with a through association" do
- author = Author.includes(:comments_with_order_and_conditions, :posts).first
- assert_no_queries { assert_equal 2, author.comments_with_order_and_conditions.size }
- assert_no_queries { assert_equal 5, author.posts.size, "should not cache a subset of the association" }
- end
end