【发布时间】:2015-11-24 03:06:34
【问题描述】:
在 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 有可能吗,还是我必须查询表?
【问题讨论】:
-
x 应该是您新创建的行,因此它的 id 为 no ? x.getId()
-
我不知道为什么,但是当我在测试时,我只看到了一个
[1]记录,现在我看到了完整的对象,谢谢
标签: mysql node.js sequelize.js