不要怂,就是干,撸起袖子干!

Commit 2c14876b by Seth Samuel

Rename undestroy to restore

1 parent 76f1ea51
......@@ -759,13 +759,13 @@ module.exports = (function() {
};
/**
* Undestroy the row corresponding to this instance. Only available for paranoid models.
* Restore the row corresponding to this instance. Only available for paranoid models.
*
* @param {Object} [options={}]
*
* @return {Promise<undefined>}
*/
Instance.prototype.undestroy = function(options) {
Instance.prototype.restore = function(options) {
if (!this.Model._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
options = Utils._.extend({
......@@ -778,7 +778,7 @@ module.exports = (function() {
return Promise.try(function() {
// Run before hook
if (options.hooks) {
return self.Model.runHooks('beforeUndestroy', self, options);
return self.Model.runHooks('beforeRestore', self, options);
}
}).then(function() {
self.dataValues[self.Model._timestampAttributes.deletedAt] = null;
......@@ -786,7 +786,7 @@ module.exports = (function() {
}).tap(function(result) {
// Run after hook
if (options.hooks) {
return self.Model.runHooks('afterUndestroy', self, options);
return self.Model.runHooks('afterRestore', self, options);
}
});
};
......
......@@ -1389,16 +1389,16 @@ module.exports = (function() {
};
/**
* Undestroy multiple instances if `paranoid` is enabled.
* Restore multiple instances if `paranoid` is enabled.
*
* @param {Object} [options.where] Filter the undestroy
* @param {Boolean} [options.hooks=true] Run before / after bulk undestroy hooks?
* @param {Boolean} [options.individualHooks=false] If set to true, undestroy will find all records within the where parameter and will execute before / after bulkUndestroy hooks on each row
* @param {Object} [options.where] Filter the restore
* @param {Boolean} [options.hooks=true] Run before / after bulk restore hooks?
* @param {Boolean} [options.individualHooks=false] If set to true, restore will find all records within the where parameter and will execute before / after bulkRestore hooks on each row
* @param {Number} [options.limit] How many rows to undelete
*
* @return {Promise<undefined>}
*/
Model.prototype.undestroy = function(options) {
Model.prototype.restore = function(options) {
if (!this._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
options = Utils._.extend({
......@@ -1416,13 +1416,13 @@ module.exports = (function() {
return Promise.try(function() {
// Run before hook
if (options.hooks) {
return self.runHooks('beforeBulkUndestroy', options);
return self.runHooks('beforeBulkRestore', options);
}
}).then(function() {
// Get daos and run beforeDestroy hook on each record individually
if (options.individualHooks) {
return self.findAll({where: options.where}, {transaction: options.transaction}).map(function(instance) {
return self.runHooks('beforeUndestroy', instance, options).then(function() {
return self.runHooks('beforeRestore', instance, options).then(function() {
return instance;
});
}).then(function(_instances) {
......@@ -1439,13 +1439,13 @@ module.exports = (function() {
// Run afterDestroy hook on each record individually
if (options.individualHooks) {
return Promise.map(instances, function(instance) {
return self.runHooks('afterUndestroy', instance, options);
return self.runHooks('afterRestore', instance, options);
});
}
}).tap(function() {
// Run after hook
if (options.hooks) {
return self.runHooks('afterBulkUndestroy', options);
return self.runHooks('afterBulkRestore', options);
}
}).then(function(affectedRows) {
return affectedRows;
......
......@@ -1304,13 +1304,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe("undestroy", function(){
describe("restore", function(){
it("returns an error if the model is not paranoid", function(){
var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){
return user.destroy().then(function(){
return self.User.undestroy({where : {username : "Peter"}}).then(function(){
return self.User.restore({where : {username : "Peter"}}).then(function(){
expect(false).to.be.ok
}, function(err){
expect(err).to.exist
......@@ -1336,7 +1336,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
return ParanoidUser.sync({ force: true }).then(function() {
return ParanoidUser.bulkCreate(data).then(function() {
return ParanoidUser.destroy({where: {secretValue: '42'}}).then(function() {
return ParanoidUser.undestroy({where : {secretValue: '42'}}).then(function() {
return ParanoidUser.restore({where : {secretValue: '42'}}).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
......
......@@ -1798,13 +1798,13 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
describe("undestroy", function(){
describe("restore", function(){
it("returns an error if the model is not paranoid", function(){
var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){
return user.destroy().then(function(){
return user.undestroy().then(function(){
return user.restore().then(function(){
expect(false).to.be.ok
}, function(err){
expect(err).to.exist
......@@ -1831,7 +1831,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
return ParanoidUser.bulkCreate(data).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
return user.destroy().then(function() {
return user.undestroy().then(function() {
return user.restore().then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!