Sha256: 7e7fa7b17e207097705190a6df9b9b823dcb5ec261d279dce18d3e6479a2c157

Contents?: true

Size: 1.28 KB

Versions: 19

Compression:

Stored size: 1.28 KB

Contents

module ActiveRecord
  module Core
    def initialize_dup(other) # :nodoc:
      @attributes = @attributes.deep_dup
      # CPK
      #@attributes.reset(@primary_key)
      Array(self.class.primary_key).each {|key| @attributes.reset(key)}

      _run_initialize_callbacks

      @new_record               = true
      @destroyed                = false
      @_start_transaction_state = nil
      @transaction_state        = nil

      super
    end

    module ClassMethods
      def find(*ids) # :nodoc:
        # We don't have cache keys for this stuff yet
        return super unless ids.length == 1
        return super if block_given? ||
            primary_key.nil? ||
            scope_attributes? ||
            columns_hash.key?(inheritance_column) && !base_class?

        # CPK
        return super if self.composite?

        id = ids.first

        return super if StatementCache.unsupported_value?(id)

        key = primary_key

        statement = cached_find_by_statement(key) { |params|
          where(key => params.bind).limit(1)
        }

        record = statement.execute([id], connection)&.first
        unless record
          raise ::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with '#{key}'=#{id}", name, key, id)
        end
        record
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.9 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.8 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.8 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.7 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.6 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.7 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.6 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.5 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.5 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.4 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.4 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.3 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.3 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.2 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.2 lib/composite_primary_keys/core.rb
composite_primary_keys-14.0.1 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.1 lib/composite_primary_keys/core.rb
composite_primary_keys-13.0.0 lib/composite_primary_keys/core.rb
composite_primary_keys-12.0.10 lib/composite_primary_keys/core.rb