Skip to content

Commit e30fc4a

Browse files
committed
Reset @target in subclasses
Collection associations point to an array target, where singular associations will point to a single object. An "empty" (or "reset") association has different meaning depending on whether it's single or a collection. This commit changes the reset method to be specific to the type of association. This is related to rails#48671
1 parent 0b04c15 commit e30fc4a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

activerecord/lib/active_record/associations/association.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def initialize(owner, reflection)
5252
# Resets the \loaded flag to +false+ and sets the \target to +nil+.
5353
def reset
5454
@loaded = false
55-
@target = nil
5655
@stale_state = nil
5756
end
5857

activerecord/lib/active_record/associations/singular_association.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def reader
1414
target
1515
end
1616

17+
# Resets the \loaded flag to +false+ and sets the \target to +nil+.
18+
def reset
19+
super
20+
@target = nil
21+
end
22+
1723
# Implements the writer method, e.g. foo.bar= for Foo.belongs_to :bar
1824
def writer(record)
1925
replace(record)

0 commit comments

Comments
 (0)