Skip to content

Commit

Permalink
jashkenas#4103 check if obj is Model in Collection.get (jashkenas#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksladkov authored and akre54 committed Dec 1, 2016
1 parent df3366d commit 7da4ed7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
get: function(obj) {
if (obj == null) return void 0;
return this._byId[obj] ||
this._byId[this.modelId(obj.attributes || obj)] ||
this._byId[this.modelId(this._isModel(obj) ? obj.attributes : obj)] ||
obj.cid && this._byId[obj.cid];
},

Expand Down
5 changes: 5 additions & 0 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2074,4 +2074,9 @@
assert.equal(fired, false);
});

QUnit.test('get models with `attributes` key', function(assert) {
var model = {id: 1, attributes: {}};
var collection = new Backbone.Collection([model]);
assert.ok(collection.get(model));
});
})(QUnit);

0 comments on commit 7da4ed7

Please sign in to comment.