Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom idAttribute not recognized in Sync #12

Open
micahalcorn opened this issue Aug 9, 2013 · 5 comments
Open

Custom idAttribute not recognized in Sync #12

micahalcorn opened this issue Aug 9, 2013 · 5 comments

Comments

@micahalcorn
Copy link

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?

@viezel
Copy link
Owner

viezel commented Aug 9, 2013

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?

@micahalcorn
Copy link
Author

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"

@viezel
Copy link
Owner

viezel commented Aug 9, 2013

Roger. Please let me know if you find a solution.

@micahalcorn
Copy link
Author

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.

@PierreGUI
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants