mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
null and undefined are invalid ids.
This commit is contained in:
@@ -854,7 +854,7 @@
|
||||
}
|
||||
if (model && event === 'change:' + model.idAttribute) {
|
||||
delete this._byId[model.previous(model.idAttribute)];
|
||||
this._byId[model.id] = model;
|
||||
if (model.id != null) this._byId[model.id] = model;
|
||||
}
|
||||
this.trigger.apply(this, arguments);
|
||||
}
|
||||
|
||||
@@ -589,4 +589,14 @@ $(document).ready(function() {
|
||||
ok(c.at(0) instanceof Model);
|
||||
});
|
||||
|
||||
test("null and undefined are invalid ids.", function() {
|
||||
var model = new Backbone.Model({id: 1});
|
||||
var collection = new Backbone.Collection([model]);
|
||||
model.set({id: null});
|
||||
ok(!collection.get('null'));
|
||||
model.set({id: 1});
|
||||
model.set({id: undefined});
|
||||
ok(!collection.get('undefined'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user