sivashanmugam kannan sivashanmugam kannan - 1 year ago 123
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 ]




"error": {
"name": "Error",
"status": 400,
"message": "id property (undefined) cannot be updated from undefined to undefined",
"statusCode": 400,

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

Answer Source

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 ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download