Flowdock
method

new_record

Importance_0
Ruby on Rails latest stable (v5.2.3) - 0 notes - Class: ActiveRecord::Associations::HasOneAssociation

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

new_record(replace_existing) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# 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
Register or log in to add new notes.