Skip to content

Instantly share code, notes, and snippets.

@fl0w
Created May 24, 2018 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fl0w/937fa304721016f595dcf679cd1bee84 to your computer and use it in GitHub Desktop.
Save fl0w/937fa304721016f595dcf679cd1bee84 to your computer and use it in GitHub Desktop.
naive collection cascade destroy
async destroy (options = {}) {
const destroyed = this.clone().reset()
destroyed._events = this._events // Copy referens to events
if (!this.length) return destroyed
await destroyed.triggerThen('destroying', this, options)
for (const model of this) {
await model.destroy(options)
destroyed.add(model)
}
await destroyed.triggerThen('destroyed', destroyed, options)
return destroyed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment