sivashanmugam kannan sivashanmugam kannan - 16 days ago 11
MySQL Question

Update id value of a model in loopback

Updating id of a model seems to be not possible, Tried to update through POST method ,[ DB: mysql ]

METHOD : PUT

http://localhost:3000/api/company/google

REQUEST BODY
{
"name":"alphabet"
}

RESPONSE BODY
"error": {
"name": "Error",
"status": 400,
"message": "id property (undefined) cannot be updated from undefined to undefined",
"statusCode": 400,
"stack":"....etc"
}


If not possible through built in paths in client side how to do that in server side through loopback
nodeAPI
functions available to update a id of a model?
Been trying this for two days, No luck.
Thanks.

Answer

I do not think it is possible to update the ID of model's instance, because that would break all relations to this instance.

Look at this post that indicates the key of a model should never be changed for MySQL tables

That being said, I don't think you actually need to update your ID in your situation. Keep idInjection to false, and do not set id for property name.

Then you can execute this one request

POST http://localhost:3000/api/company/update?where[name]=Google

{
   "name": "alphabet"
}

Is this helpful ?