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

Commit db2f882d by Sascha Depold

lol, mixed camelize and underscored -> fixed

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