当我使用Waterline的create方法时,它不会返回新记录的ID [英] When i use Waterline's create method, it doesn't return the new record's ID
问题描述
当我使用Waterline的create方法创建新记录时,将返回创建的对象,但没有ID.如何获取最后插入的对象的ID?
When i create a new record using Waterline's create method, the created object is returned, but without it's ID. How can I get the id of the last inserted object?
我在mariadb上使用mysql适配器,如果有什么不同
I'm using the mysql adapter on mariadb if it makes any difference
推荐答案
似乎您做错了什么.我没有对水线进行任何其他配置,无论如何,每次我使用new
查询以及记录时,它都会返回id
.
It seems like you're probably doing something wrong. I have not done any additional configuration to waterline, anyway it returns id
every time when I use new
query as well as record at all.
在大多数情况下,我不会在Sails模型中创建id
字段,自动生成对我来说很好.如果您自己创建id
字段,请确保其具有正确的配置. 此问题表明该ID必须为
In most cases I don't create id
field in sails model, auto-generation works quite fine for me. If you create id
field by yourself ensure that it has correct configuration. This issue shows that id requires to be
autoIncrement: true
否则,它实际上不会返回带有查询的ID.
otherwise it really don't return id with queries.
完整字段应如下所示:
id: {
type: 'integer',
primaryKey: true,
autoIncrement: true
}
这篇关于当我使用Waterline的create方法时,它不会返回新记录的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!