aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-02-09 09:47:16 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-02-09 09:53:35 +0900
commit52c9af6c51fbf686762ad2330f36fe9f8ce3c5d7 (patch)
treebc79aa09af37cda16be31d02c90d3a41aebcaab5 /activerecord
parent0613533f78763be88337187951ab7d76106ace53 (diff)
parent42a3c92c8c43a16185800e357bd95104288d761c (diff)
downloadrails-52c9af6c51fbf686762ad2330f36fe9f8ce3c5d7.tar.gz
rails-52c9af6c51fbf686762ad2330f36fe9f8ce3c5d7.tar.bz2
rails-52c9af6c51fbf686762ad2330f36fe9f8ce3c5d7.zip
Merge pull request #31934 from fatkodima/fix-has_many_through-dumping
Fix marshaling of models with `has_many :through` associations
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/association.rb4
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 7667c6ed8b..364f1fe74f 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -156,9 +156,9 @@ module ActiveRecord
reset
end
- # We can't dump @reflection since it contains the scope proc
+ # We can't dump @reflection and @through_reflection since it contains the scope proc
def marshal_dump
- ivars = (instance_variables - [:@reflection]).map { |name| [name, instance_variable_get(name)] }
+ ivars = (instance_variables - [:@reflection, :@through_reflection]).map { |name| [name, instance_variable_get(name)] }
[@reflection.name, ivars]
end
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 25118b26f5..3b3d4037b9 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -46,6 +46,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
Reader.create person_id: 0, post_id: 0
end
+ def test_marshal_dump
+ preloaded = Post.includes(:first_blue_tags).first
+ assert_equal preloaded, Marshal.load(Marshal.dump(preloaded))
+ end
+
def test_preload_sti_rhs_class
developers = Developer.includes(:firms).all.to_a
assert_no_queries do