When i use Waterline's create method, it doesn't return the new record's ID

为君一笑 提交于 2019-12-11 08:27:38

问题


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?

I'm using the mysql adapter on mariadb if it makes any difference


回答1:


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.

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

otherwise it really don't return id with queries.

Full field should look like this:

id: {
    type: 'integer', 
    primaryKey: true,
    autoIncrement: true
}


来源:https://stackoverflow.com/questions/28103271/when-i-use-waterlines-create-method-it-doesnt-return-the-new-records-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!