Sha256: 7ed4e0398e2c2ed1d657eb5609a0be5a64f3da36cea96358f8b886dbb46b884d

Contents?: true

Size: 898 Bytes

Versions: 5

Compression:

Stored size: 898 Bytes

Contents

module ActiveRecord
  module ConnectionAdapters
    module DatabaseStatements
      def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
        sql, binds = to_sql_and_binds(arel, binds)
        value = exec_insert(sql, name, binds, pk, sequence_name)

        if pk.is_a?(Array) && !value.empty?
          # This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
          # auto incremented field
          id_value || pk.map {|key| value.first[key]}
        elsif pk.is_a?(Array)
          # This is CPK, but we don't know what autoincremented fields were updated. So return nil, which means
          # the existing id_value of the model will be used.
          id_value || Array.new(pk.size)
        else
          id_value || last_inserted_id(value)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
composite_primary_keys-12.0.8 lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
composite_primary_keys-12.0.6 lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
composite_primary_keys-12.0.5 lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
composite_primary_keys-12.0.4 lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
composite_primary_keys-12.0.3 lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb