From 6971da0514e8447f974c179b45c347f635794691 Mon Sep 17 00:00:00 2001 From: "Fabio M. Costa" Date: Thu, 20 Dec 2012 17:33:44 -0500 Subject: [PATCH] Ensure that fetch calls update if only {add: true} option is passed, instead of calling reset --- backbone.js | 2 +- test/collection.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index fbbc4e82f..d2c006f7d 100644 --- a/backbone.js +++ b/backbone.js @@ -859,7 +859,7 @@ var collection = this; var success = options.success; options.success = function(resp, status, xhr) { - var method = options.update ? 'update' : 'reset'; + var method = (options.update || options.add) ? 'update' : 'reset'; collection[method](resp, options); if (success) success(collection, resp, options); }; diff --git a/test/collection.js b/test/collection.js index 966330b8d..e5183de7b 100644 --- a/test/collection.js +++ b/test/collection.js @@ -407,6 +407,19 @@ $(document).ready(function() { equal(counter, 1); }); + test("ensure fetch calls 'update' if only {add: true} option is passed", 1, function() { + var collection = new Backbone.Collection; + var counter = 0; + collection.update = function(models) { + counter++; + return this; + }; + collection.url = '/test'; + collection.fetch({add: true}); + this.syncArgs.options.success([]); + equal(counter, 1); + }); + test("create", 4, function() { var collection = new Backbone.Collection; collection.url = '/test';