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

Commit fa791396 by Ricardo Graça

Fix issue #418 - timestamps always returned.

1 parent 60ebce19
Showing with 7 additions and 7 deletions
......@@ -252,12 +252,12 @@ module.exports = (function() {
}
DAOFactory.prototype.build = function(values, options) {
options = options || {}
options = options || {isNewRecord: true}
var self = this
, instance = new this.DAO(values, this.options)
, instance = new this.DAO(values, this.options, options.isNewRecord)
instance.isNewRecord = options.hasOwnProperty('isNewRecord') ? options.isNewRecord : true
instance.isNewRecord = options.isNewRecord
return instance
}
......
......@@ -4,13 +4,13 @@ var Utils = require("./utils")
, DataTypes = require("./data-types")
module.exports = (function() {
var DAO = function(values, options) {
var DAO = function(values, options, isNewRecord) {
var self = this;
this.__options = options;
this.hasPrimaryKeys = options.hasPrimaryKeys;
this.selectedValues = values;
initAttributes.call(this, values)
initAttributes.call(this, values, isNewRecord)
if (this.hasDefaultValues) {
Utils._.each(this.defaultValues, function (value, name) {
......@@ -269,7 +269,7 @@ module.exports = (function() {
// private
var initAttributes = function(values) {
var initAttributes = function(values, isNewRecord) {
// add all passed values to the dao and store the attribute names in this.attributes
for (var key in values) {
if (values.hasOwnProperty(key)) {
......@@ -281,7 +281,7 @@ module.exports = (function() {
// a newly created dao has no id
var defaults = this.hasPrimaryKeys ? {} : { id: null }
if(this.__options.timestamps) {
if(this.__options.timestamps && isNewRecord) {
defaults[this.__options.underscored ? 'created_at' : 'createdAt'] = new Date()
defaults[this.__options.underscored ? 'updated_at' : 'updatedAt'] = new Date()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!