Search code examples
javascriptundefinedloopbackupdate-attributes

Loopback fails on updateAttributes id property undefined to undefined


So yesterday, I wasted 4 to 6 hours with this issue, and couldn't find anything that could help on the internet, so I'll share it here. It happened on a simple updateAttributes, couldn't update, I was always getting this error:

id property (undefined) cannot be updated from undefined to undefined

From inside the code, or from the remote method end point, at first an upsert was "trolling" me, I was logging the values on the "after save" observe, and it was there, but never persisted to the database, I tryed the endpoint directly on the explorer, same error, I removed all my acls, I had a lot maybe that was causing some kind of conflict, nothing, I even removed all my model methods, I had many observe 'before save', 'after save', 'access', 'loaded', maybe something was being messed in there, nothing, I added a beforeRemote('prototype.updateAttributes',...); the values where there, still was not saving or getting that dang error, until I finally realized when trying to remove the relations too, I saw I had 3 properties with the "id": true in my model json file D: (I copy pasted those to add new properties I required) and it was it, that was the dang conflict, I cryed and I went to sleep T^T


Solution

  • So the answer was:

    Check you json model definition there might be wrong properties defined as 'id' ("id": true)