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
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
