def assign_nested_attributes_for_one_to_one_association(association_name, attributes, assignment_opts = {})
      options = self.nested_attributes_options[association_name]
      attributes = attributes.with_indifferent_access

      if (options[:update_only] || !attributes['id'].blank?) && (record = send(association_name)) &&
          (options[:update_only] || record.id.to_s == attributes['id'].to_s)
        assign_to_or_mark_for_destruction(record, attributes, options[:allow_destroy], assignment_opts) unless call_reject_if(association_name, attributes)

      elsif attributes['id'].present? && !assignment_opts[:without_protection]
        raise_nested_attributes_record_not_found(association_name, attributes['id'])

      elsif !reject_new_record?(association_name, attributes)
        method = "build_#{association_name}"
        if respond_to?(method)
          send(method, attributes.except(*unassignable_keys(assignment_opts)), assignment_opts)
        else
          raise ArgumentError, "Cannot build association #{association_name}. Are you trying to build a polymorphic one-to-one association?"
        end
      end
    end
def assign_nested_attributes_for_one_to_one_association(association_name, attributes, assignment_opts = {})
      options = self.nested_attributes_options[association_name]
      attributes = attributes.with_indifferent_access

      if (options[:update_only] || !attributes['id'].blank?) && (record = send(association_name)) &&
          (options[:update_only] || record.id.to_s == attributes['id'].to_s)
        assign_to_or_mark_for_destruction(record, attributes, options[:allow_destroy], assignment_opts) unless call_reject_if(association_name, attributes)

      elsif attributes['id'].present? && !assignment_opts[:without_protection]
        raise_nested_attributes_record_not_found(association_name, attributes['id'])

      elsif !reject_new_record?(association_name, attributes)
        method = "build_#{association_name}"
        if respond_to?(method)
          send(method, attributes.except(*unassignable_keys(assignment_opts)), assignment_opts)
        else
          raise ArgumentError, "Cannot build association #{association_name}. Are you trying to build a polymorphic one-to-one association?"
        end
      end
    end
Assigns the given attributes to the association.

 If update_only is false and the given attributes include an <tt>:id</tt>
 that matches the existing record's id, then the existing record will be
 modified. If update_only is true, a new record is only created when no
 object exists. Otherwise a new record will be built.

 If the given attributes include a matching <tt>:id</tt> attribute, or
 update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
 then the existing record will be marked for destruction.