Custom idAttribute not recognized in Sync
My Rails/Mongoid app returns JSON with the _id attribute rather than id, so I have set the model.definition.config.idAttribute to '_id'. This works fine in the create case, but model[model.idAttribute] returns falsy in other cases. It appears that model.id would return the appropriate _id string. Am I doing something wrong, or should I modify my restapi.js?
hmm.. im not sure. it should work how you explained.
"model[model.idAttribute] returns falsy in other cases" What could that be, and in which use cases?
I know for sure that it happens on the update case. On line 197, model[model.idAttribute] returns undefined. At this breakpoint, the objects looks like this:
model
> idAttribute "_id"
> id "5205332fd03cca8dcc000002"
> attributes
> _id "5205332fd03cca8dcc000002"
Roger. Please let me know if you find a solution.
I'm convinced that the use of model[model.idAttribute] is inappropriate here. The idAttribute's purpose is for mapping to the remote server and for determining whether or not an identifier needs to be generated by the client. Regardless of the idAttribute value, the Backbone model will always have an id. idAttribute simply syncs the model.id with the model.attributes[idAttribute]. I am going to revert back to model.id in the appropriate places. Please let me know if I have missed something.
Hi there !
Have the exact same problem with my custom id (using Parse.com -> "objectId").
model[model.idAttribute] is null
model.get(model.idAttribute) returns my id, so does model.id
Example: When I updade, got error "[REST API] ERROR: MISSING MODEL ID" because if (!model.[model.idAttribute]) is true (when it souldn't be).
For now I've replaced all occurrences of model[idAttribute] with model.get(model.idAttribute). Am I right ?
Cheers