How could I send the last inserted id when creating a new entry in sequlize?
Currently this is the model way of creating a new value:
function post( request, response ) {
models.xxx.create( {
field1: request.body.field1,
field2: request.body.field2
} )
.then( function ( x ) {
//x = 0 || 1;
response.json( x );
//What I would like to send is the `id` of the new row
} );
}
Is that possible with sequelize, or do I have to query the table?
I am using MSSQL dialect and the return result is a row of new created data. Access object key "id" will show you the last increment id used.
.then( function ( x ) {
//x = new created row
response.json( x.id );
} );
Actually the promise function returns the newly created row, but for some reason I could only see [1]
at my console, now I see the object.
.then( function ( x ) {
//x = new created row
response.json( x );
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With