Fix #1112 - options.model sets collection.model.

This commit is contained in:
Brad Dunbar
2012-03-18 22:28:08 -04:00
parent 01fb4149e1
commit 9ffc84c9fe
2 changed files with 8 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);
});
});