Skip to content

Commit 087260d

Browse files
authored
Merge pull request rails#51713 from Shopify/stale-state-casting
Don't cast `stale_state` to String
2 parents 8ba2b7f + 2cadcb2 commit 087260d

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

activerecord/lib/active_record/associations/belongs_to_association.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def invertible_for?(record)
148148
end
149149

150150
def stale_state
151-
result = owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
152-
result && result.to_s
151+
owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
153152
end
154153
end
155154
end

activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def raise_on_type_mismatch!(record)
4141
end
4242

4343
def stale_state
44-
foreign_key = super
45-
foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s]
44+
if foreign_key = super
45+
[foreign_key, owner[reflection.foreign_type]]
46+
end
4647
end
4748
end
4849
end

activerecord/lib/active_record/associations/through_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def construct_join_attributes(*records)
8282
def stale_state
8383
if through_reflection.belongs_to?
8484
Array(through_reflection.foreign_key).filter_map do |foreign_key_column|
85-
owner[foreign_key_column] && owner[foreign_key_column].to_s
85+
owner[foreign_key_column]
8686
end.presence
8787
end
8888
end

activerecord/test/cases/marshal_serialization_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def test_deserializing_rails_6_1_marshal_with_loaded_association_cache
3333
assert_equal "Have a nice day", topic.content
3434
assert_predicate topic.association(:replies), :loaded?
3535
assert_predicate topic.replies.first.association(:topic), :loaded?
36-
assert_same topic, topic.replies.first.topic
3736
end
3837

3938
def test_deserializing_rails_7_1_marshal_basic

0 commit comments

Comments
 (0)