1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #31934 from fatkodima/fix-has_many_through-dumping

Fix marshaling of models with `has_many :through` associations
This commit is contained in:
Ryuta Kamizono 2018-02-09 09:47:16 +09:00
commit 52c9af6c51
2 changed files with 7 additions and 2 deletions

View file

@ -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

View file

@ -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