[Pkg-javascript-commits] [backbone] 48/74: fixing more model.collection in initialize.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.0
in repository backbone.

commit 65c52763d32948f02f19ab38047ac1bf31f44ab0
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Thu Nov 4 23:52:21 2010 -0400

    fixing more model.collection in initialize.
---
 backbone.js   | 10 +++++++---
 test/model.js |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/backbone.js b/backbone.js
index 87d7372..29ae3db 100644
--- a/backbone.js
+++ b/backbone.js
@@ -464,9 +464,13 @@
     // Create a new instance of a model in this collection. After the model
     // has been created on the server, it will be added to the collection.
     create : function(model, options) {
+      var coll = this;
       options || (options = {});
-      if (!(model instanceof Backbone.Model)) model = new this.model(model);
-      var coll = model.collection = this;
+      if (!(model instanceof Backbone.Model)) {
+        model = new this.model(model, {collection: coll});
+      } else {
+        model.collection = coll;
+      }
       var success = function(nextModel, resp) {
         coll.add(nextModel);
         if (options.success) options.success(nextModel, resp);
@@ -500,7 +504,7 @@
     _add : function(model, options) {
       options || (options = {});
       if (!(model instanceof Backbone.Model)) {
-        model = new this.model(model);
+        model = new this.model(model, {collection: this});
       }
       var already = this.getByCid(model);
       if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
diff --git a/test/model.js b/test/model.js
index daf1fbb..5e46fce 100644
--- a/test/model.js
+++ b/test/model.js
@@ -32,6 +32,7 @@ $(document).ready(function() {
     var Model = Backbone.Model.extend({
       initialize: function() {
         this.one = 1;
+        equals(this.collection, collection);
       }
     });
     var model = new Model({}, {collection: collection});

-- 
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