Skip to content

Commit

Permalink
Use merge: true by default for Collection.reset. Ref #320
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulUithol committed Apr 9, 2013
1 parent c31ea90 commit 77eb89d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions backbone-relational.js
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@
*/
var reset = Backbone.Collection.prototype.__reset = Backbone.Collection.prototype.reset;
Backbone.Collection.prototype.reset = function( models, options ) {
options = _.extend( { merge: true }, options );
reset.call( this, models, options );

if ( this.model.prototype instanceof Backbone.RelationalModel ) {
Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,22 @@ $(document).ready(function() {
equal( lion.get( 'name' ), 'Simba' );
});

test( "reset should use `merge: true` by default", function() {
var nodeList = new NodeList();

nodeList.add( [ { id: 1 }, { id: 2, parent: 1 } ] );

var node1 = nodeList.get( 1 ),
node2 = nodeList.get( 2 );

ok( node2.get( 'parent' ) === node1 );
ok( !node1.get( 'parent' ) );

nodeList.reset( [ { id: 1, parent: 2 } ] );

ok( node1.get( 'parent' ) === node2 );
});

test( "add/remove/update (with `add`, `remove` and `merge` options)", function() {
var coll = new AnimalCollection();

Expand Down

0 comments on commit 77eb89d

Please sign in to comment.