diff --git a/backbone.js b/backbone.js index d63cd850..37626fc2 100644 --- a/backbone.js +++ b/backbone.js @@ -138,13 +138,13 @@ if (defaults = getValue(this, 'defaults')) { attributes = _.extend({}, defaults, attributes); } + if (options && options.collection) this.collection = options.collection; this.attributes = {}; this._escapedAttributes = {}; this.cid = _.uniqueId('c'); this.set(attributes, {silent : true}); this._changed = false; this._previousAttributes = _.clone(this.attributes); - if (options && options.collection) this.collection = options.collection; this.initialize(attributes, options); }; diff --git a/test/collection.js b/test/collection.js index c08fa2b1..c0c8a79a 100644 --- a/test/collection.js +++ b/test/collection.js @@ -448,4 +448,16 @@ $(document).ready(function() { ok(attrs === models[0]); }); + test("#714: access `model.collection` in a brand new model.", 2, function() { + var col = new Backbone.Collection; + var Model = Backbone.Model.extend({ + set: function(attrs) { + equals(attrs.prop, 'value'); + equals(this.collection, col); + } + }); + col.model = Model; + col.create({prop: 'value'}); + }); + });