Merge pull request #46790 from lazaronixon/singular-association-refactor

Small refactor on build singular association
This commit is contained in:
Jean Boussier 2022-12-22 09:17:48 +01:00 committed by GitHub
commit 68664aee48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -87,6 +87,10 @@ module ActiveRecord
replace(record, false)
end
def replace_keys(record, force: false)
# Has one association doesn't have foreign keys to replace.
end
def remove_target!(method)
case method
when :delete

View File

@ -57,7 +57,7 @@ module ActiveRecord
reflection.klass.transaction do
record = build(attributes, &block)
saved = record.save
set_new_record(record)
replace_keys(record, force: true)
raise RecordInvalid.new(record) if !saved && raise_error
record
end