Sha256: c4a553252003d59defb7efd17d832bff67338ae9d35d27f3d8a7caf6b0ad04ca

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module ActiveRecord
  module Core
    def init_internals_with_cpk
      init_internals_without_cpk
      # Remove cpk array from attributes, fixes to_json
      @attributes.delete(self.class.primary_key) if self.composite?
    end
    alias_method_chain :init_internals, :cpk

    def initialize_dup(other)
      cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
      self.class.initialize_attributes(cloned_attributes, :serialized => false)
      # CPK
      # cloned_attributes.delete(self.class.primary_key)
      Array(self.class.primary_key).each {|key| cloned_attributes.delete(key.to_s)}
      @attributes = cloned_attributes
      
      run_callbacks(:initialize) unless _initialize_callbacks.empty?

      @changed_attributes = {}
      self.class.column_defaults.each do |attr, orig_value|
        @changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr])
      end

      @aggregation_cache = {}
      @association_cache = {}
      @attributes_cache  = {}

      @new_record  = true

      ensure_proper_type
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
composite_primary_keys-6.0.8 lib/composite_primary_keys/core.rb
composite_primary_keys-6.0.7 lib/composite_primary_keys/core.rb
composite_primary_keys-6.0.6 lib/composite_primary_keys/core.rb
composite_primary_keys-6.0.5 lib/composite_primary_keys/core.rb
composite_primary_keys-6.0.3 lib/composite_primary_keys/core.rb
composite_primary_keys-6.0.1 lib/composite_primary_keys/core.rb