method

replace

Importance_0
v3.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::BelongsToPolymorphicAssociation
replace(record) public

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/belongs_to_polymorphic_association.rb, line 5
      def replace(record)
        if record.nil?
          @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil
        else
          @target = (AssociationProxy === record ? record.target : record)

          @owner[@reflection.primary_key_name] = record_id(record)
          @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s

          @updated = true
        end

        set_inverse_instance(record, @owner)
        loaded
        record
      end
Register or log in to add new notes.