Flowdock
method

replace

Importance_0
v2.2.1 - 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 4
      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
          @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s

          @updated = true
        end

        loaded
        record
      end
Register or log in to add new notes.