From ece51d2383b3e972ff5ba64eb152f324b7fb6d9e Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 4 Nov 2010 23:45:48 -0400 Subject: [PATCH] Allowing a collection to be passed into a model via the options. --- backbone.js | 1 + test/model.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 7c0ccfd8..87d7372e 100644 --- a/backbone.js +++ b/backbone.js @@ -112,6 +112,7 @@ this.cid = _.uniqueId('c'); this.set(attributes || {}, {silent : true}); this._previousAttributes = _.clone(this.attributes); + if (options && options.collection) this.collection = options.collection; if (this.initialize) this.initialize(attributes, options); }; diff --git a/test/model.js b/test/model.js index 312a6f32..daf1fbb9 100644 --- a/test/model.js +++ b/test/model.js @@ -34,8 +34,9 @@ $(document).ready(function() { this.one = 1; } }); - var model = new Model; + var model = new Model({}, {collection: collection}); equals(model.one, 1); + equals(model.collection, collection); }); test("Model: initialize with attributes and options", function() {