Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. function rollbackModel() {
  2. const model = this.get('model');
  3.  
  4. if (isArray(model)) {
  5. model.forEach(m => this._deepRollback(m));
  6. } else {
  7. this._deepRollback(model);
  8. }
  9. }
  10.  
  11. function _deepRollback(model) {
  12. model.reload().then(m => {
  13. m.eachRelationship((key, relationship) => {
  14. if (relationship.kind === 'belongsTo') {
  15. this._rollBack(get(m, key));
  16. } else if (relationship.kind === 'hasMany') {
  17. get(m, key).forEach(m => this._rollBack(m));
  18. }
  19. });
  20. });
  21. }
  22.  
  23. function _rollBack(model) {
  24. if(!isNone(model)) {
  25. model = get(model, 'content') || model;
  26. if(model.rollbackAttributes && model.get('hasDirtyAttributes')) {
  27. model.rollbackAttributes();
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement