Sha256: abda09b7bc2287d0f1cf596dfc2fc1ab44db398ec9b8e2adba061ae136b2b2c6

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

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

      _run_initialize_callbacks

      @new_record               = true
      @destroyed                = false
      @_start_transaction_state = {}
      @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.include?(inheritance_column)

        # 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 RecordNotFound.new("Couldn't find #{name} with '#{primary_key}'=#{id}",
                                   name, primary_key, id)
        end
        record
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
composite_primary_keys-12.0.0.rc4 lib/composite_primary_keys/core.rb
composite_primary_keys-12.0.0.rc3 lib/composite_primary_keys/core.rb
composite_primary_keys-12.0.0.rc2 lib/composite_primary_keys/core.rb
composite_primary_keys-12.0.0.rc1 lib/composite_primary_keys/core.rb