method
new_record
rails latest stable - Class:
ActiveRecord::Associations::HasOneAssociation
new_record(replace_existing)private
No documentation available.
# File activerecord/lib/active_record/associations/has_one_association.rb, line 111
def new_record(replace_existing)
# Make sure we load the target first, if we plan on replacing the existing
# instance. Otherwise, if the target has not previously been loaded
# elsewhere, the instance we create will get orphaned.
load_target if replace_existing
record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) do
yield @reflection
end
if replace_existing
replace(record, true)
else
record[@reflection.primary_key_name] = @owner.id unless @owner.new_record?
self.target = record
set_inverse_instance(record, @owner)
end
record
end