method

insert

Importance_0
v5.1.7 - Show latest stable - 0 notes - Class: ActiveRecord::Relation
insert(values) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/relation.rb, line 36
    def insert(values) # :nodoc:
      primary_key_value = nil

      if primary_key && Hash === values
        primary_key_value = values[values.keys.find { |k|
          k.name == primary_key
        }]

        if !primary_key_value && klass.prefetch_primary_key?
          primary_key_value = klass.next_sequence_value
          values[arel_attribute(klass.primary_key)] = primary_key_value
        end
      end

      im = arel.create_insert
      im.into @table

      substitutes, binds = substitute_values values

      if values.empty? # empty insert
        im.values = Arel.sql(connection.empty_insert_statement_value)
      else
        im.insert substitutes
      end

      @klass.connection.insert(
        im,
        "SQL",
        primary_key || false,
        primary_key_value,
        nil,
        binds)
    end
Register or log in to add new notes.