aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorfatkodima <fatkodima123@gmail.com>2018-02-08 16:13:15 +0200
committerfatkodima <fatkodima123@gmail.com>2018-02-08 16:13:56 +0200
commit42a3c92c8c43a16185800e357bd95104288d761c (patch)
treea63a12bdf7b37291eb6153d1db3641f3382a2839 /activerecord
parentd7f9adf7941574d0a40a165739938d28f278bd77 (diff)
downloadrails-42a3c92c8c43a16185800e357bd95104288d761c.tar.gz
rails-42a3c92c8c43a16185800e357bd95104288d761c.tar.bz2
rails-42a3c92c8c43a16185800e357bd95104288d761c.zip
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.rb6
2 files changed, 8 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..f465404694 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,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
Reader.create person_id: 0, post_id: 0
end
+ def test_marshal_dump
+ post = posts :welcome
+ preloaded = Post.includes(:first_blue_tags).find(post.id)
+ 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