diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index cf87d308cf4..a38d2f8d480 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -148,8 +148,7 @@ module ActiveRecord end def stale_state - result = owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) } - result && result.to_s + owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) } end end end diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb index 298fa1011e5..a6e5ee3b03c 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -41,8 +41,9 @@ module ActiveRecord end def stale_state - foreign_key = super - foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s] + if foreign_key = super + [foreign_key, owner[reflection.foreign_type]] + end end end end diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index e3680bac939..7389ecc787a 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -82,7 +82,7 @@ module ActiveRecord def stale_state if through_reflection.belongs_to? Array(through_reflection.foreign_key).filter_map do |foreign_key_column| - owner[foreign_key_column] && owner[foreign_key_column].to_s + owner[foreign_key_column] end.presence end end diff --git a/activerecord/test/cases/marshal_serialization_test.rb b/activerecord/test/cases/marshal_serialization_test.rb index c72f0efb3de..70cd9d14567 100644 --- a/activerecord/test/cases/marshal_serialization_test.rb +++ b/activerecord/test/cases/marshal_serialization_test.rb @@ -33,7 +33,6 @@ class MarshalSerializationTest < ActiveRecord::TestCase assert_equal "Have a nice day", topic.content assert_predicate topic.association(:replies), :loaded? assert_predicate topic.replies.first.association(:topic), :loaded? - assert_same topic, topic.replies.first.topic end def test_deserializing_rails_7_1_marshal_basic