Open usernameisregistered opened 4 years ago
The attribute Id had been updated, because the idAttribute was updated. Not the other way around.
@usernameisregistered If you console.log(hacker)
, you will find an object that looks like this:
{
id: undefined,
// idAttribute inherited from Backbone.Model.prototype, default 'id'
attributes: {
name: 'name',
idAttribute: 'nameId'
}
// more properties
}
You probably meant to do this:
// Define a new type of model which obtains its `id` from the `nameId` attribute.
var Hacker = Backbone.Model.extend({
idAttribute: 'nameId'
});
// Create a new instance of the above model type.
var hacker = new Hacker({
nameId: 'name'
});
Now console.log(hacker)
will output the following instead:
{
id 'name',
idAttribute: 'nameId',
attributes: {
nameId: 'name'
}
// other properties
}
Does this answer your question?
https://github.com/jashkenas/backbone/blob/0b1c2e3fce3156fcb9819b8bbf8885456e4e1055/backbone.js#L519
The attribute Id has been updated, does the attribute nameId also need to be updated? I don't think it is necessary to update the attribute id, just the nameId