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

Commit 1b9b44cd by sdepold

set created at if field list is passed to save method

1 parent d9b280a5
Showing with 16 additions and 3 deletions
......@@ -85,9 +85,21 @@ module.exports = (function() {
// only those fields will be updated
DAO.prototype.save = function(fields) {
var self = this
, values = fields ? {} : this.values;
, values = fields ? {} : this.values
, updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt'
, createdAtAttr = this.__options.underscored ? 'created_at' : 'createdAt'
if(fields) {
if(self.__options.timestamps) {
if(fields.indexOf(updatedAtAttr) === -1) {
fields.push(updatedAtAttr)
}
if(fields.indexOf(createdAtAttr) === -1) {
fields.push(createdAtAttr)
}
}
fields.forEach(function(field) {
if(self.values[field]) {
values[field] = self.values[field]
......@@ -95,7 +107,6 @@ module.exports = (function() {
});
}
var updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt'
if(this.__options.timestamps && this.hasOwnProperty(updatedAtAttr)) {
var now = new Date()
......@@ -189,6 +200,7 @@ module.exports = (function() {
var self = this
var readOnlyAttributes = Utils._.keys(this.__factory.primaryKeys)
readOnlyAttributes.push('id')
readOnlyAttributes.push('createdAt')
readOnlyAttributes.push('updatedAt')
......@@ -264,9 +276,10 @@ module.exports = (function() {
defaults[this.__options.underscored ? 'created_at' : 'createdAt'] = new Date()
defaults[this.__options.underscored ? 'updated_at' : 'updatedAt'] = new Date()
if(this.__options.paranoid)
if(this.__options.paranoid) {
defaults[this.__options.underscored ? 'deleted_at' : 'deletedAt'] = null
}
}
Utils._.map(defaults, function(value, attr) {
if(!self.hasOwnProperty(attr)) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!