Open nhitchins opened 11 years ago
I need this too, as I'm using mongo backed storage with "_id" attributes, and I just added the property
MyModel = syncedModel.extend({
idAttribute: "_id"
}, {
modelName: "MyModel"
});
This seems to be working -- am I missing something?
Davis,
The client.js file in the ss-backbone libs has this in the Initialization method (line ~50):
registerModel(model, modelname, attrs.id || model.cid);
I've replaced it with:
this.idAttribute = this.idAttribute || 'id'; registerModel(model, modelname, attrs[this.idAttribute] || model.cid);
There are also a few other places in that same client.js file that referene the .id attribute which i've just replaced with [this.idAttribute]
@nhitchins ,
Apologies for the late response here. Nice solution - feel free to submit a pull request and I'll merge in the change.
A useful enhancement would be to allow for the model 'id' attribute to be specifed as per: http://backbonejs.org/#Model-idAttribute
then in the ss-backbone client.js file modify any direct reference to 'id'to use the model class idAttribute: registerModel(model, modelname, attrs[this.idAttribute] || model.cid);
obviously you just need to check the property exists otherwise set it's default to 'id'