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

Commit a79773dc by Sascha Depold

freezeTableNames for getting tablenames as passed

1 parent f0f55ae0
...@@ -9,7 +9,7 @@ var ModelDefinition = module.exports = function(name, attributes, options) { ...@@ -9,7 +9,7 @@ var ModelDefinition = module.exports = function(name, attributes, options) {
this.options = options || {} this.options = options || {}
this.options.timestamps = this.options.hasOwnProperty('timestamps') ? this.options.timestamps : true this.options.timestamps = this.options.hasOwnProperty('timestamps') ? this.options.timestamps : true
this.name = name this.name = name
this.tableName = Utils.pluralize(name) this.tableName = this.options.freezeTableName ? name : Utils.pluralize(name)
this.attributes = Utils.simplifyAttributes(attributes) this.attributes = Utils.simplifyAttributes(attributes)
this.modelManager = null // defined by model-manager during addModel this.modelManager = null // defined by model-manager during addModel
this.associations = {} this.associations = {}
......
...@@ -54,5 +54,13 @@ module.exports = { ...@@ -54,5 +54,13 @@ module.exports = {
'timestamp columns should be underscored if underscored is passed': function() { 'timestamp columns should be underscored if underscored is passed': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true, underscored: 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"})
},
'tablenames should be as passed if they are frozen': function() {
var User = sequelize.define('User', {}, {freezeTableName: true})
assert.eql(User.tableName, 'User')
},
'tablenames should be pluralized if they are not frozen': function() {
var User = sequelize.define('User', {}, {freezeTableName: false})
assert.eql(User.tableName, 'Users')
} }
} }
\ 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!