From 9610019133171532726de48670dee1d5b37684cb Mon Sep 17 00:00:00 2001 From: Kim Joar Bekkelund Date: Mon, 21 Jan 2013 10:41:23 +0100 Subject: [PATCH] Collection#create returns result from Model#save --- backbone.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backbone.js b/backbone.js index 13f60aebb..dbd459d78 100644 --- a/backbone.js +++ b/backbone.js @@ -871,16 +871,17 @@ // wait for the server to agree. create: function(model, options) { options = options ? _.clone(options) : {}; - if (!(model = this._prepareModel(model, options))) return false; - if (!options.wait) this.add(model, options); + if (!(model = this._prepareModel(model, options))) return Backbone.Deferred.reject(); + if (!options.wait) model = this.add(model, options); var collection = this; var success = options.success; options.success = function(resp) { - if (options.wait) collection.add(model, options); + if (options.wait) model = collection.add(model, options); if (success) success(model, resp, options); }; - model.save(null, options); - return model; + return model.save(null, options).then(function() { + return model; + }); }, // **parse** converts a response into a list of models to be added to the