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

Commit b9d8b61e by Sascha Depold

Merge branch 'dao-duplications' of git://github.com/whentomanage/sequelize into …

…whentomanage-dao-duplications
2 parents dafcf1da 27124e95
Showing with 15 additions and 0 deletions
...@@ -141,6 +141,11 @@ module.exports = (function() { ...@@ -141,6 +141,11 @@ module.exports = (function() {
} }
options.omitNull = globalOptions.omitNull options.omitNull = globalOptions.omitNull
// if you call "define" multiple times for the same daoName, do not clutter the factory
if(this.isDefined(daoName)) {
this.daoFactoryManager.removeDAO(this.daoFactoryManager.getDAO(daoName))
}
var factory = new DAOFactory(daoName, attributes, options) var factory = new DAOFactory(daoName, attributes, options)
this.daoFactoryManager.addDAO(factory.init(this.daoFactoryManager)) this.daoFactoryManager.addDAO(factory.init(this.daoFactoryManager))
return factory return factory
......
...@@ -36,6 +36,16 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -36,6 +36,16 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
expect(User.tableName).toEqual('SuperUsers') expect(User.tableName).toEqual('SuperUsers')
}) })
it("uses checks to make sure dao factory isnt leaking on multiple define", function() {
var User = this.sequelize.define('SuperUser', {}, { freezeTableName: false })
var factorySize = this.sequelize.daoFactoryManager.all.length
var User2 = this.sequelize.define('SuperUser', {}, { freezeTableName: false })
var factorySize2 = this.sequelize.daoFactoryManager.all.length
expect(factorySize).toEqual(factorySize2)
})
it("attaches class and instance methods", function() { it("attaches class and instance methods", function() {
var User = this.sequelize.define('UserWithClassAndInstanceMethods', {}, { var User = this.sequelize.define('UserWithClassAndInstanceMethods', {}, {
classMethods: { doSmth: function(){ return 1 } }, classMethods: { doSmth: function(){ return 1 } },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!