Fix #2296 get works with 0 as a model id

This commit is contained in:
Casey Foster
2013-02-20 09:08:31 -08:00
parent 6d3aed44d2
commit 21a875b2c5
2 changed files with 4 additions and 2 deletions

View File

@@ -726,7 +726,7 @@
// Get a model from the set by id.
get: function(obj) {
if (obj == null) return void 0;
return this._byId[obj.id || obj.cid || obj];
return this._byId[obj.id != null ? obj.id : obj.cid || obj];
},
// Get the model at the given index.

View File

@@ -62,8 +62,10 @@ $(document).ready(function() {
strictEqual(collection.last().get('a'), 4);
});
test("get", 5, function() {
test("get", 6, function() {
equal(col.get(0), d);
var d2 = d.clone();
equal(col.get(d2), d);
equal(col.get(2), b);
equal(col.get({id: 1}), c);
equal(col.get(c.clone()), c);