当我使用 Waterline 的创建方法时,它不会返回新记录的 ID [英] When i use Waterline's create method, it doesn't return the new record's ID

查看:35
本文介绍了当我使用 Waterline 的创建方法时,它不会返回新记录的 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 的创建方法时,它不会返回新记录的 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆