return 最后插入的 id sequelize
return last inserted id sequelize
在 sequlize 中创建新条目时如何发送最后插入的 ID?
目前这是创建新值的模型方式:
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
} );
}
sequelize 可以吗,还是我必须查询 table?
实际上 promise 函数 returns 新创建的行,但由于某种原因我只能在我的控制台上看到 [1]
,现在我看到了对象。
.then( function ( x ) {
//x = new created row
response.json( x );
} );
https://github.com/sequelize/sequelize/issues/5499#issuecomment-480528090
将@@IDENTITY 用于原始 SELECT 查询
我正在使用 MSSQL 方言,return 结果是一行新创建的数据。访问对象键“id”将显示上次使用的增量 ID。
.then( function ( x ) {
//x = new created row
response.json( x.id );
} );
在 sequlize 中创建新条目时如何发送最后插入的 ID?
目前这是创建新值的模型方式:
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
} );
}
sequelize 可以吗,还是我必须查询 table?
实际上 promise 函数 returns 新创建的行,但由于某种原因我只能在我的控制台上看到 [1]
,现在我看到了对象。
.then( function ( x ) {
//x = new created row
response.json( x );
} );
https://github.com/sequelize/sequelize/issues/5499#issuecomment-480528090
将@@IDENTITY 用于原始 SELECT 查询
我正在使用 MSSQL 方言,return 结果是一行新创建的数据。访问对象键“id”将显示上次使用的增量 ID。
.then( function ( x ) {
//x = new created row
response.json( x.id );
} );