diff --git a/lib/orm-timestamps.js b/lib/orm-timestamps.js index be2f970..c7ffa36 100644 --- a/lib/orm-timestamps.js +++ b/lib/orm-timestamps.js @@ -44,21 +44,21 @@ function Plugin(db, opts) { if(opts.timestamp !== true) return; - if(persist && options.createdProperty !== false) + if(options.persist && options.createdProperty !== false) properties[options.createdProperty] = options.dbtype; - if(persist && options.modifiedProperty !== false) + if(options.persist && options.modifiedProperty !== false) properties[options.modifiedProperty] = options.dbtype; opts.hooks = opts.hooks || {}; if(options.createdProperty !== false) wrapHook(opts.hooks, 'beforeCreate', function() { - if(!persist && this[options.createdProperty] === undefined) + if(options.persist) + this[options.createdProperty] = options.now(); + else if(this[options.createdProperty] === undefined) Object.defineProperty(this, options.createdProperty, { value: options.now() - }) - else if(persist) - this[options.createdProperty] = options.now(); + }); }); if(options.modifiedProperty !== false)