mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 21:38:00 -05:00
Fixes #714, assign model.collection early, so that those overriding set() can use it from the get-go.
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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'});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user