When i use Waterline#39;s create method, it doesn#39;t return the new record#39;s ID(当我使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我使用 Waterline 的创建方法时,它不会返回新记录的 ID
基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
