File tree Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def _marshal_dump_7_1
25
25
payload = [ attributes_for_database , new_record? ]
26
26
27
27
cached_associations = self . class . reflect_on_all_associations . select do |reflection |
28
- association_cached? ( reflection . name )
28
+ association_cached? ( reflection . name ) && association ( reflection . name ) . loaded?
29
29
end
30
30
31
31
unless cached_associations . empty?
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def build_entry(record)
80
80
81
81
def add_cached_associations ( record , entry )
82
82
record . class . normalized_reflections . each_value do |reflection |
83
- if record . association_cached? ( reflection . name )
83
+ if record . association_cached? ( reflection . name ) && record . association ( reflection . name ) . loaded?
84
84
entry << reflection . name << encode ( record . association ( reflection . name ) . target )
85
85
end
86
86
end
Original file line number Diff line number Diff line change @@ -78,6 +78,10 @@ def test_rails_7_1_rountrip
78
78
assert_same topic , reply . topic
79
79
end
80
80
81
+ topic . association ( :open_replies )
82
+ assert_equal true , topic . association_cached? ( :open_replies )
83
+ assert_not_predicate topic . association ( :open_replies ) , :loaded?
84
+
81
85
topic = Marshal . load ( Marshal . dump ( topic ) )
82
86
83
87
assert_not_predicate topic , :new_record?
@@ -86,6 +90,8 @@ def test_rails_7_1_rountrip
86
90
assert_equal "Have a nice day" , topic . content
87
91
assert_predicate topic . association ( :replies ) , :loaded?
88
92
93
+ assert_not_predicate topic . association ( :open_replies ) , :loaded?
94
+
89
95
assert_not_equal 0 , topic . replies . size
90
96
topic . replies . each do |reply |
91
97
assert_same topic , reply . topic
You can’t perform that action at this time.
0 commit comments