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:
commit
52c9af6c51
2 changed files with 7 additions and 2 deletions
|
@ -156,9 +156,9 @@ module ActiveRecord
|
||||||
reset
|
reset
|
||||||
end
|
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
|
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]
|
[@reflection.name, ivars]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
Reader.create person_id: 0, post_id: 0
|
Reader.create person_id: 0, post_id: 0
|
||||||
end
|
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
|
def test_preload_sti_rhs_class
|
||||||
developers = Developer.includes(:firms).all.to_a
|
developers = Developer.includes(:firms).all.to_a
|
||||||
assert_no_queries do
|
assert_no_queries do
|
||||||
|
|
Loading…
Reference in a new issue