Skip to content

Commit

Permalink
Only trigger a local 'destroy' event when fetchRelated fails; fixes P…
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulUithol committed Feb 9, 2012
1 parent 723a698 commit 7169df1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backbone-relational.js
Expand Up @@ -1004,7 +1004,7 @@
error: function() {
var args = arguments;
_.each( models, function( model ) {
model.destroy();
model.trigger( 'destroy', model, model.collection, options );
options.error && options.error.apply( model, args );
});
},
Expand All @@ -1021,7 +1021,7 @@
var opts = _.defaults(
{
error: function() {
model.destroy();
model.trigger( 'destroy', model, model.collection, options );
options.error && options.error.apply( model, arguments );
}
},
Expand Down
8 changes: 4 additions & 4 deletions test/tests.js
Expand Up @@ -537,11 +537,11 @@ $(document).ready(function() {
ok( requests[ 0 ].url === '/animal/set/lion-2;zebra-2/' );
equal( zoo.get('animals').length, 2 );

// Triggering the 'error' callback should destroy both of the fetched models
// Triggering the 'error' callback (some error occured during fetching) should trigger the 'destroy' event
// on both fetched models, but should NOT actually make 'delete' requests to the server!
var numRequests = window.requests.length;
requests[ 0 ].error();
// Trigger the 'success' callback for both 'delete' calls to fire the 'destroy' event
window.requests[ window.requests.length - 1 ].success();
window.requests[ window.requests.length - 2 ].success();
ok( window.requests.length === numRequests, "An error occured when fetching, but no DELETE requests are made to the server while handling local cleanup." );

equal( zoo.get( 'animals' ).length, 0, "Both animals are destroyed" );
equal( errorCount, 2, "The error callback executed successfully for both models" );
Expand Down

0 comments on commit 7169df1

Please sign in to comment.