Skip to content

Commit 4279b47

Browse files
committed
Small refactor on build singular association
1 parent de40fc6 commit 4279b47

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activerecord/lib/active_record/associations/has_one_association.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def set_new_record(record)
8787
replace(record, false)
8888
end
8989

90+
def replace_keys(record, force: false)
91+
# Has one association doesn't have foreign keys to replace.
92+
end
93+
9094
def remove_target!(method)
9195
case method
9296
when :delete

activerecord/lib/active_record/associations/singular_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _create_record(attributes, raise_error = false, &block)
5757
reflection.klass.transaction do
5858
record = build(attributes, &block)
5959
saved = record.save
60-
set_new_record(record)
60+
replace_keys(record, force: true)
6161
raise RecordInvalid.new(record) if !saved && raise_error
6262
record
6363
end

0 commit comments

Comments
 (0)