I just added idAttribute: '_id'
to some models in my BackboneJS app for use with MongoDB on the server-side. At first, this works as expected, when looking at the model in a view later, this.model.id
is set to the same value as _id
. However, if I use the get
method on the model for id
, it returns undefined
. I could just switch to using this.model.id
instead of this.model.get('id')
, it just seemed that using the get
method was a cleaner and more formal way of retrieving model data. Is this by design? Should I just stop using model.get
everywhere for consistency sake? Thanks.
My understanding is that you still would have to use this.model.get('_id'). Telling backbone which property uniquely identifies your model doesn't change the name of the property in the attributes hash.