instance method initialize_copy

Ruby on Rails 3.0.20

Since v3.0.20 Last seen in v3.0.20

Signature

initialize_copy(other)

Cloned objects have no id assigned and are treated as new records. Note that this is a “shallow” clone as it copies the object’s attributes only, not its associations. The extent of a “deep” clone is application specific and is therefore left to the application to implement according to its need.

Parameters

other req
Source
# File activerecord/lib/active_record/base.rb, line 1426
      def initialize_copy(other)
        _run_after_initialize_callbacks if respond_to?(:_run_after_initialize_callbacks)
        cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
        cloned_attributes.delete(self.class.primary_key)

        @attributes = cloned_attributes

        @changed_attributes = {}
        attributes_from_column_definition.each do |attr, orig_value|
          @changed_attributes[attr] = orig_value if field_changed?(attr, orig_value, @attributes[attr])
        end

        clear_aggregation_cache
        clear_association_cache
        @attributes_cache = {}
        @new_record = true
        ensure_proper_type

        populate_with_current_scope_attributes
      end

Defined in activerecord/lib/active_record/base.rb line 1426 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Base

Type at least 2 characters to search.

↑↓ navigate · open · esc close