Is there any easy way to revert a model to its previously values saved in the database?
Fortunately sugar has made most of our job easier…:)
To revert back a model to its previous values, you can just add the below line to your js code.
This file contains 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
model.revertAttributes(); |
If you want to check whether any of the attributes has changed or not. You can do it by adding the below line.
This file contains 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
var changedAttributes = model.changedAttributes(model.getSyncedAttributes()); | |
if (!_.isEmpty(changedAttributes)) { | |
//some attributes's value has changed | |
} |
Note: model represents the backbone model which corresponds to your sugar record.
If you are trying this in record.js controller, you can replace model with this.model.
Follow my blog to get daily tips……..:)