Method: ActiveRecord::ConnectionAdapters::DatabaseStatements#insert
- Defined in:
- lib/active_record/connection_adapters/abstract/database_statements.rb
#insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) ⇒ Object
Returns the last auto-generated ID from the affected table.
id_value will be returned unless the value is nil, in
which case the database will attempt to calculate the last inserted
id and return that value.
If the next id was calculated in advance (as in Oracle), it should be
passed in as id_value.
94 95 96 97 98 |
# File 'lib/active_record/connection_adapters/abstract/database_statements.rb', line 94 def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) sql, binds = sql_for_insert(to_sql(arel, binds), pk, id_value, sequence_name, binds) value = exec_insert(sql, name, binds, pk, sequence_name) id_value || last_inserted_id(value) end |