在环回中更新模型的 id 值
Update id value of a model in loopback
更新模型的 id 似乎不可能(数据库:mysql)。
我尝试了以下 PUT 请求:
PUT http://localhost:3000/api/company/google
{
"name":"alphabet"
}
回复:
"error": {
"name": "Error",
"status": 400,
"message": "id property (undefined) cannot be updated from undefined to undefined",
"statusCode": 400,
"stack":"....etc"
}
如果无法通过内置 REST API 我该怎么做?我可以使用节点 API 服务器端来更新模型的 id 吗?
已经试了两天了,运气不好。
谢谢
我认为不可能更新模型实例的 ID,因为那样会破坏与该实例的所有关系。
看看这个 post,它表明永远不应为 MySQL 个表更改模型的键
话虽这么说,但我认为根据您的情况,您实际上不需要更新您的 ID。保持 idInjection
为 false,不要为 属性 name
.
设置 id
那你就可以执行这个请求了
POST http://localhost:3000/api/company/update?where[name]=Google
{
"name": "alphabet"
}
这有帮助吗?
更新模型的 id 似乎不可能(数据库:mysql)。
我尝试了以下 PUT 请求:
PUT http://localhost:3000/api/company/google
{
"name":"alphabet"
}
回复:
"error": {
"name": "Error",
"status": 400,
"message": "id property (undefined) cannot be updated from undefined to undefined",
"statusCode": 400,
"stack":"....etc"
}
如果无法通过内置 REST API 我该怎么做?我可以使用节点 API 服务器端来更新模型的 id 吗?
已经试了两天了,运气不好。 谢谢
我认为不可能更新模型实例的 ID,因为那样会破坏与该实例的所有关系。
看看这个 post,它表明永远不应为 MySQL 个表更改模型的键
话虽这么说,但我认为根据您的情况,您实际上不需要更新您的 ID。保持 idInjection
为 false,不要为 属性 name
.
id
那你就可以执行这个请求了
POST http://localhost:3000/api/company/update?where[name]=Google
{
"name": "alphabet"
}
这有帮助吗?