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

Commit a57bd01d by sdepold

renamed ModelManager to ModelFactoryManager

1 parent 8f84cc19
# v1.3.1 #
- [REFACTORING] renamed ModelManager to ModelFactoryManager
# v1.3.0 #
- [REFACTORING] Model#all is now a function and not a getter.
- [REFACTORING] Renamed ModelDefinition to ModelFactory
......
......@@ -48,7 +48,7 @@ module.exports = (function() {
combinedTableAttributes[this.identifier] = {type:DataTypes.INTEGER, primaryKey: true}
combinedTableAttributes[this.foreignIdentifier] = {type:DataTypes.INTEGER, primaryKey: true}
this.connectorModel = this.source.modelManager.sequelize.define(this.combinedName, combinedTableAttributes)
this.connectorModel = this.source.modelFactoryManager.sequelize.define(this.combinedName, combinedTableAttributes)
if(!this.isSelfAssociation) this.target.associations[this.associationAccessor].connectorModel = this.connectorModel
this.connectorModel.sync()
......
......@@ -119,7 +119,7 @@ module.exports = (function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
var storedModel = self.sequelize.modelManager.getModel('SequelizeMeta')
var storedModel = self.sequelize.modelFactoryManager.getModel('SequelizeMeta')
, SequelizeMeta = storedModel
if(!storedModel) {
......
module.exports = (function() {
var ModelManager = function(sequelize) {
var ModelFactoryManager = function(sequelize) {
this.models = []
this.sequelize = sequelize
}
ModelManager.prototype.addModel = function(model) {
ModelFactoryManager.prototype.addModel = function(model) {
this.models.push(model)
return model
}
ModelManager.prototype.removeModel = function(model) {
ModelFactoryManager.prototype.removeModel = function(model) {
this.models = this.models.filter(function(_model) {
return _model.name != model.name
})
}
ModelManager.prototype.getModel = function(modelName) {
ModelFactoryManager.prototype.getModel = function(modelName) {
var model = this.models.filter(function(model) {
return model.name == modelName
})
......@@ -24,9 +24,9 @@ module.exports = (function() {
return !!model ? model[0] : null
}
ModelManager.prototype.__defineGetter__('all', function() {
ModelFactoryManager.prototype.__defineGetter__('all', function() {
return this.models
})
return ModelManager
return ModelFactoryManager
})()
......@@ -19,7 +19,7 @@ module.exports = (function() {
this.name = name
this.tableName = this.options.freezeTableName ? name : Utils.pluralize(name)
this.rawAttributes = attributes
this.modelManager = null // defined in init function
this.modelFactoryManager = null // defined in init function
this.associations = {}
// extract validation
......@@ -33,7 +33,7 @@ module.exports = (function() {
})
Object.defineProperty(ModelFactory.prototype, 'QueryInterface', {
get: function() { return this.modelManager.sequelize.getQueryInterface() }
get: function() { return this.modelFactoryManager.sequelize.getQueryInterface() }
})
Object.defineProperty(ModelFactory.prototype, 'QueryGenerator', {
......@@ -48,8 +48,8 @@ module.exports = (function() {
get: function() { return this.primaryKeyCount > 0 }
})
ModelFactory.prototype.init = function(modelManager) {
this.modelManager = modelManager
ModelFactory.prototype.init = function(modelFactoryManager) {
this.modelFactoryManager = modelFactoryManager
addDefaultAttributes.call(this)
addOptionalClassMethods.call(this)
......@@ -189,7 +189,7 @@ module.exports = (function() {
var query = function() {
var args = Utils._.map(arguments, function(arg, _) { return arg })
, s = this.modelManager.sequelize
, s = this.modelFactoryManager.sequelize
// add this as the second argument
if(arguments.length == 1) args.push(this)
......
......@@ -22,7 +22,7 @@ module.exports = (function() {
Utils._.extend(Model.prototype, Mixin.prototype)
Object.defineProperty(Model.prototype, 'sequelize', {
get: function(){ return this.__factory.modelManager.sequelize }
get: function(){ return this.__factory.modelFactoryManager.sequelize }
})
Object.defineProperty(Model.prototype, 'QueryInterface', {
......@@ -256,7 +256,7 @@ module.exports = (function() {
var query = function() {
var args = Utils._.map(arguments, function(arg, _) { return arg })
, s = this.__factory.modelManager.sequelize
, s = this.__factory.modelFactoryManager.sequelize
args.push(this)
return s.query.apply(s, args)
......
var Utils = require("./utils")
, ModelFactory = require("./model-factory")
, DataTypes = require('./data-types')
, ModelManager = require("./model-manager")
, ModelFactoryManager = require("./model-factory-manager")
, Migrator = require("./migrator")
, QueryInterface = require("./query-interface")
......@@ -26,7 +26,7 @@ module.exports = (function() {
var ConnectorManager = require("./dialects/" + this.options.dialect + "/connector-manager")
this.modelManager = new ModelManager(this)
this.modelFactoryManager = new ModelFactoryManager(this)
this.connectorManager = new ConnectorManager(this, this.config)
}
......@@ -55,7 +55,7 @@ module.exports = (function() {
var factory = new ModelFactory(modelName, attributes, options)
this.modelManager.addModel(factory.init(this.modelManager))
this.modelFactoryManager.addModel(factory.init(this.modelFactoryManager))
return factory
}
......@@ -89,7 +89,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer
self.modelManager.models.forEach(function(model) { chainer.add(model.sync(options)) })
self.modelFactoryManager.models.forEach(function(model) { chainer.add(model.sync(options)) })
chainer
.run()
......@@ -104,7 +104,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer
self.modelManager.models.forEach(function(model) { chainer.add(model.drop()) })
self.modelFactoryManager.models.forEach(function(model) { chainer.add(model.drop()) })
chainer
.run()
......
......@@ -102,7 +102,7 @@ describe('HasMany', function() {
expect(Task.attributes.UserId).toBeUndefined()
expect(User.attributes.UserId).toBeUndefined()
var models = sequelize.modelManager.models.filter(function(model) {
var models = sequelize.modelFactoryManager.models.filter(function(model) {
return (model.tableName == (Task.tableName + User.tableName))
})
......@@ -122,7 +122,7 @@ describe('HasMany', function() {
expect(Task.attributes.user_id).toBeUndefined()
expect(User.attributes.user_id).toBeUndefined()
var models = sequelize.modelManager.models.filter(function(model) {
var models = sequelize.modelFactoryManager.models.filter(function(model) {
return (model.tableName == (Task.tableName + User.tableName))
})
......@@ -136,7 +136,7 @@ describe('HasMany', function() {
User.hasMany(Task, { foreignKey: 'person_id' })
Task.hasMany(User, { foreignKey: 'work_item_id' })
var models = sequelize.modelManager.models.filter(function(model) {
var models = sequelize.modelFactoryManager.models.filter(function(model) {
return (model.tableName == (Task.tableName + User.tableName))
})
......@@ -227,7 +227,7 @@ describe('HasMany', function() {
Person.hasMany(Person, {as: 'CoWorkers'})
Person.sync({force: true}).success(function() {
var modelNames = sequelize.modelManager.models.map(function(model) { return model.tableName })
var modelNames = sequelize.modelFactoryManager.models.map(function(model) { return model.tableName })
, expectation = ["Persons", "ChildrenPersons", "CoWorkersPersons", "FriendsPersons"]
expectation.forEach(function(ex) {
......
......@@ -10,7 +10,7 @@ Factories.prototype.Model = function(modelName, options, callback, count) {
, models = []
this.helpers.async(function(done) {
var Model = self.sequelize.modelManager.getModel(modelName)
var Model = self.sequelize.modelFactoryManager.getModel(modelName)
var create = function(cb) {
Model.create(options).on('success', function(model) {
......
......@@ -19,7 +19,7 @@ describe('Associations', function() {
it("should create a table wp_table1wp_table2s", function() {
Helpers.async(function(done) {
expect(sequelize.modelManager.getModel('wp_table1swp_table2s')).toBeDefined()
expect(sequelize.modelFactoryManager.getModel('wp_table1swp_table2s')).toBeDefined()
done()
})
})
......
......@@ -36,9 +36,9 @@ describe('Sequelize', function() {
describe('define', function() {
it("adds a new model to the model manager", function() {
expect(sequelize.modelManager.all.length).toEqual(0)
expect(sequelize.modelFactoryManager.all.length).toEqual(0)
sequelize.define('foo', { title: Sequelize.STRING })
expect(sequelize.modelManager.all.length).toEqual(1)
expect(sequelize.modelFactoryManager.all.length).toEqual(1)
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!