File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed
lib/active_record/associations Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 1+ * Prevent error when using ` force_reload: true ` on an unassigned polymorphic
2+ belongs_to association.
3+
4+ Fixes #20426 .
5+
6+ * James Dabbs*
7+
18* Correctly raise ` ActiveRecord::AssociationTypeMismatch ` when assigning
29 a wrong type to a namespaced association.
310
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ module Associations
33 class SingularAssociation < Association #:nodoc:
44 # Implements the reader method, e.g. foo.bar for Foo.has_one :bar
55 def reader ( force_reload = false )
6- if force_reload
6+ if force_reload && klass
77 klass . uncached { reload }
88 elsif !loaded? || stale_target?
99 reload
Original file line number Diff line number Diff line change @@ -318,9 +318,11 @@ def test_with_condition
318318 def test_polymorphic_association_class
319319 sponsor = Sponsor . new
320320 assert_nil sponsor . association ( :sponsorable ) . send ( :klass )
321+ assert_nil sponsor . sponsorable ( force_reload : true )
321322
322323 sponsor . sponsorable_type = '' # the column doesn't have to be declared NOT NULL
323324 assert_nil sponsor . association ( :sponsorable ) . send ( :klass )
325+ assert_nil sponsor . sponsorable ( force_reload : true )
324326
325327 sponsor . sponsorable = Member . new :name => "Bert"
326328 assert_equal Member , sponsor . association ( :sponsorable ) . send ( :klass )
You can’t perform that action at this time.
0 commit comments