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

Commit dcd24011 by Sascha Depold

added isDefined for sequelize

1 parent 1d87f43b
Showing with 20 additions and 4 deletions
...@@ -65,18 +65,21 @@ module.exports = (function() { ...@@ -65,18 +65,21 @@ module.exports = (function() {
Sequelize.prototype.define = function(daoName, attributes, options) { Sequelize.prototype.define = function(daoName, attributes, options) {
options = options || {} options = options || {}
if(this.options.define) {
if(this.options.define)
options = Sequelize.Utils.merge(options, this.options.define) options = Sequelize.Utils.merge(options, this.options.define)
}
options.omitNull = this.options.omitNull options.omitNull = this.options.omitNull
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
} }
Sequelize.prototype.isDefined = function(daoName) {
var daos = this.daoFactoryManager.daos
return (daos.filter(function(dao) { return dao.name === daoName }).length !== 0)
}
Sequelize.prototype.import = function(path) { Sequelize.prototype.import = function(path) {
if (!this.importCache[path]) { if (!this.importCache[path]) {
var defineCall = require(path) var defineCall = require(path)
......
...@@ -20,4 +20,17 @@ describe('Sequelize', function() { ...@@ -20,4 +20,17 @@ describe('Sequelize', function() {
expect(1).toEqual(1) expect(1).toEqual(1)
}) })
}) })
describe('isDefined', function() {
it("returns false if the dao wasn't defined before", function() {
expect(this.sequelize.isDefined('Project')).toBeFalse()
})
it("returns true if the dao was defined before", function() {
this.sequelize.define('Project', {
name: Helpers.Sequelize.STRING
})
expect(this.sequelize.isDefined('Project')).toBeTrue()
})
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!