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

Commit ce1e0099 by Sascha Depold

setting deletedAt is working

1 parent 40d67cae
Showing with 26 additions and 1 deletions
......@@ -65,13 +65,25 @@ Model.prototype.save = function() {
}
Model.prototype.destroy = function() {
return this.query(QueryGenerator.deleteQuery(this.definition.tableName, this.id))
if(this.options.timestamps && this.options.safeDelete) {
this[this.options.camelcase ? 'deleted_at' : 'deletedAt'] = new Date()
return this.save()
} else {
return this.query(QueryGenerator.deleteQuery(this.definition.tableName, this.id))
}
}
Model.prototype.__defineGetter__('isNewRecord', function() {
return this.id == null
})
Model.prototype.__defineGetter__('isDeleted', function() {
var result = this.options.timestamps && this.options.safeDelete
result = result && this[this.options.camelcase ? 'deleted_at' : 'deletedAt'] != null
return result
})
Model.prototype.__defineGetter__('values', function() {
var result = {}
, self = this
......
......@@ -19,5 +19,17 @@ module.exports = {
})
})
})
},
'destroy should mark the record as deleted if safeDelete is activated': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {safeDelete:true})
User.sync({force: true}).on('success', function() {
User.create({name: 'asd', bio: 'asd'}).on('success', function(u) {
assert.isNull(u.deletedAt)
u.destroy().on('success', function(u) {
assert.isNotNull(u.deletedAt)
exit()
})
})
})
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!