[Pkg-javascript-commits] [backbone] 190/281: Fixes #714, assign model.collection early, so that those overriding set() can use it from the get-go.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit a8bd142b64fb88b3b2acc69738560c9d586164f5
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Fri Jan 13 13:18:53 2012 -0500
Fixes #714, assign model.collection early, so that those overriding set() can use it from the get-go.
---
backbone.js | 2 +-
test/collection.js | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/backbone.js b/backbone.js
index d63cd85..37626fc 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 c08fa2b..c0c8a79 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'});
+ });
+
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list