Skip to content

Commit

Permalink
Merge pull request jashkenas#1119 from braddunbar/collection-model
Browse files Browse the repository at this point in the history
Fix jashkenas#1112 - options.model sets collection.model.
  • Loading branch information
jashkenas committed Mar 19, 2012
2 parents 01fb414 + 9ffc84c commit 315d67b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@
// its models in sort order, as they're added and removed.
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.model) this.model = options.model;
if (options.comparator) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
Expand Down
7 changes: 7 additions & 0 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,11 @@ $(document).ready(function() {
ok(c.get() === undefined);
});

test("#1112 - passing options.model sets collection.model", function() {
var Model = Backbone.Model.extend({})
var c = new Backbone.Collection([{id: 1}], {model: Model});
ok(c.model === Model);
ok(c.at(0) instanceof Model);
});

});

0 comments on commit 315d67b

Please sign in to comment.