Last active
December 17, 2015 12:59
-
-
Save teddyzeenny/5613485 to your computer and use it in GitHub Desktop.
Deleting a parent when you have `dependent: :destroy` on the server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deleting a parent when you have `dependent: :destroy` on the server | |
// given `parent` a parent record | |
// `children` the parent's children | |
var childrenTransaction, parentTransaction; | |
childrenTransaction = this.get('store').transaction(); | |
childrenTransaction.add(parent); | |
parent.deleteRecord(); | |
parentTransaction.add(parent); | |
parent.one('didDelete', function() { | |
chilren.forEach(function(child) { | |
child.get('stateManager').send('becameClean'); | |
child.get('stateManager').send('finishedMaterializing'); | |
child.unloadRecord(); | |
}); | |
}); | |
parentTransaction.commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment