Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rollbackModel() {
- const model = this.get('model');
- if (isArray(model)) {
- model.forEach(m => this._deepRollback(m));
- } else {
- this._deepRollback(model);
- }
- }
- function _deepRollback(model) {
- model.reload().then(m => {
- m.eachRelationship((key, relationship) => {
- if (relationship.kind === 'belongsTo') {
- this._rollBack(get(m, key));
- } else if (relationship.kind === 'hasMany') {
- get(m, key).forEach(m => this._rollBack(m));
- }
- });
- });
- }
- function _rollBack(model) {
- if(!isNone(model)) {
- model = get(model, 'content') || model;
- if(model.rollbackAttributes && model.get('hasDirtyAttributes')) {
- model.rollbackAttributes();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement