Created
May 24, 2018 03:53
-
-
Save fl0w/937fa304721016f595dcf679cd1bee84 to your computer and use it in GitHub Desktop.
naive collection cascade destroy
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
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