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

Commit db2f882d by Sascha Depold

lol, mixed camelize and underscored -> fixed

1 parent 03f18134
......@@ -24,11 +24,11 @@ ModelDefinition.prototype.addDefaultAttributes = function() {
if(this.hasPrimaryKeys) defaultAttributes = {}
if(this.options.timestamps) {
defaultAttributes[this.options.camelcase ? 'created_at' : 'createdAt'] = {type: DataTypes.DATE, allowNull: false}
defaultAttributes[this.options.camelcase ? 'updated_at' : 'updatedAt'] = {type: DataTypes.DATE, allowNull: false}
defaultAttributes[this.options.underscored ? 'created_at' : 'createdAt'] = {type: DataTypes.DATE, allowNull: false}
defaultAttributes[this.options.underscored ? 'updated_at' : 'updatedAt'] = {type: DataTypes.DATE, allowNull: false}
if(this.options.paranoid)
defaultAttributes[this.options.camelcase ? 'deleted_at' : 'deletedAt'] = {type: DataTypes.DATE}
defaultAttributes[this.options.underscored ? 'deleted_at' : 'deletedAt'] = {type: DataTypes.DATE}
}
defaultAttributes = Utils.simplifyAttributes(defaultAttributes)
......
......@@ -17,11 +17,11 @@ var Model = module.exports = function(values, options) {
var defaults = this.options.hasPrimaryKeys ? {} : { id: null }
if(this.options.timestamps) {
defaults[this.options.camelcase ? 'created_at' : 'createdAt'] = new Date()
defaults[this.options.camelcase ? 'updated_at' : 'updatedAt'] = new Date()
defaults[this.options.underscored ? 'created_at' : 'createdAt'] = new Date()
defaults[this.options.underscored ? 'updated_at' : 'updatedAt'] = new Date()
if(this.options.paranoid)
defaults[this.options.camelcase ? 'deleted_at' : 'deletedAt'] = null
defaults[this.options.underscored ? 'deleted_at' : 'deletedAt'] = null
}
Utils._.map(defaults, function(value, attr) {
......@@ -52,7 +52,7 @@ Model.prototype.query = function() {
}
Model.prototype.save = function() {
var attr = this.options.camelcase ? 'updated_at' : 'updatedAt'
var attr = this.options.underscored ? 'updated_at' : 'updatedAt'
if(this.hasOwnProperty(attr))
this[attr] = new Date()
......@@ -67,7 +67,7 @@ Model.prototype.save = function() {
Model.prototype.destroy = function() {
if(this.options.timestamps && this.options.paranoid) {
this[this.options.camelcase ? 'deleted_at' : 'deletedAt'] = new Date()
this[this.options.underscored ? 'deleted_at' : 'deletedAt'] = new Date()
return this.save()
} else {
return this.query(QueryGenerator.deleteQuery(this.definition.tableName, this.id))
......@@ -80,7 +80,7 @@ Model.prototype.__defineGetter__('isNewRecord', function() {
Model.prototype.__defineGetter__('isDeleted', function() {
var result = this.options.timestamps && this.options.paranoid
result = result && this[this.options.camelcase ? 'deleted_at' : 'deletedAt'] != null
result = result && this[this.options.underscored ? 'deleted_at' : 'deletedAt'] != null
return result
})
......
......@@ -51,8 +51,8 @@ module.exports = {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true })
assert.eql(User.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", deletedAt:"DATETIME", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
},
'timestamp columns should be camelcase if camelcase is passed': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true, camelcase: true })
'timestamp columns should be underscored if underscored is passed': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true, underscored: true })
assert.eql(User.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", deleted_at:"DATETIME", updated_at:"DATETIME NOT NULL", created_at:"DATETIME NOT NULL"})
}
}
\ 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!