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

Commit 46c6e537 by Jan Aagaard Meier

Changed dao -> model a couple of places, updated bluebird and pointed package.js…

…on at a specific sequelize bluebird commit
1 parent bec19f6d
...@@ -315,7 +315,7 @@ module.exports = (function() { ...@@ -315,7 +315,7 @@ module.exports = (function() {
* *
* @see {DataTypes} * @see {DataTypes}
* @see {Hooks} * @see {Hooks}
* @param {String} daoName The name of the model. The model will be stored in `sequelize.models` under this name * @param {String} modelName The name of the model. The model will be stored in `sequelize.models` under this name
* @param {Object} attributes An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object, with the properties described below: * @param {Object} attributes An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object, with the properties described below:
* @param {String|DataType|Object} attributes.column The description of a database column * @param {String|DataType|Object} attributes.column The description of a database column
* @param {String|DataType} attributes.column.type A string or a data type * @param {String|DataType} attributes.column.type A string or a data type
...@@ -346,7 +346,7 @@ module.exports = (function() { ...@@ -346,7 +346,7 @@ module.exports = (function() {
* @param {String|Boolean} [options.createdAt] Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true * @param {String|Boolean} [options.createdAt] Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true
* @param {String|Boolean} [options.updatedAt] Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true * @param {String|Boolean} [options.updatedAt] Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true
* @param {String|Boolean} [options.deletedAt] Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true * @param {String|Boolean} [options.deletedAt] Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true
* @param {String} [options.tableName] Defaults to pluralized DAO name, unless freezeTableName is true, in which case it uses DAO name verbatim * @param {String} [options.tableName] Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name verbatim
* @param {Object} [options.getterMethods] Provide getter functions that work like those defined per column. If you provide a getter method with the same name as a column, it will be used to access the value of that column. If you provide a name that does not match a column, this function will act as a virtual getter, that can fetch multiple other values * @param {Object} [options.getterMethods] Provide getter functions that work like those defined per column. If you provide a getter method with the same name as a column, it will be used to access the value of that column. If you provide a name that does not match a column, this function will act as a virtual getter, that can fetch multiple other values
* @param {Object} [options.setterMethods] Provide setter functions that work like those defined per column. If you provide a setter method with the same name as a column, it will be used to update the value of that column. If you provide a name that does not match a column, this function will act as a virtual setter, that can act on and set other values, but will not be persisted * @param {Object} [options.setterMethods] Provide setter functions that work like those defined per column. If you provide a setter method with the same name as a column, it will be used to update the value of that column. If you provide a name that does not match a column, this function will act as a virtual setter, that can act on and set other values, but will not be persisted
* @param {Object} [options.instanceMethods] Provide functions that are added to each instance (DAO) * @param {Object} [options.instanceMethods] Provide functions that are added to each instance (DAO)
...@@ -361,7 +361,7 @@ module.exports = (function() { ...@@ -361,7 +361,7 @@ module.exports = (function() {
* *
* @return {Model} * @return {Model}
*/ */
Sequelize.prototype.define = function(daoName, attributes, options) { Sequelize.prototype.define = function(modelName, attributes, options) {
options = options || {}; options = options || {};
var self = this var self = this
, globalOptions = this.options; , globalOptions = this.options;
...@@ -379,13 +379,13 @@ module.exports = (function() { ...@@ -379,13 +379,13 @@ module.exports = (function() {
options.omitNull = globalOptions.omitNull; options.omitNull = globalOptions.omitNull;
options.language = globalOptions.language; options.language = globalOptions.language;
// if you call "define" multiple times for the same daoName, do not clutter the factory // if you call "define" multiple times for the same modelName, do not clutter the factory
if (this.isDefined(daoName)) { if (this.isDefined(modelName)) {
this.modelManager.removeDAO(this.modelManager.getDAO(daoName)); this.modelManager.removeDAO(this.modelManager.getDAO(modelName));
} }
options.sequelize = this; options.sequelize = this;
var factory = new Model(daoName, attributes, options); var factory = new Model(modelName, attributes, options);
this.modelManager.addDAO(factory.init(this.modelManager)); this.modelManager.addDAO(factory.init(this.modelManager));
return factory; return factory;
...@@ -394,27 +394,27 @@ module.exports = (function() { ...@@ -394,27 +394,27 @@ module.exports = (function() {
/** /**
* Fetch a DAO factory which is already defined * Fetch a DAO factory which is already defined
* *
* @param {String} daoName The name of a model defined with Sequelize.define * @param {String} modelName The name of a model defined with Sequelize.define
* @throws Will throw an error if the DAO is not define (that is, if sequelize#isDefined returns false) * @throws Will throw an error if the DAO is not define (that is, if sequelize#isDefined returns false)
* @return {Model} * @return {Model}
*/ */
Sequelize.prototype.model = function(daoName) { Sequelize.prototype.model = function(modelName) {
if (!this.isDefined(daoName)) { if (!this.isDefined(modelName)) {
throw new Error(daoName + ' has not been defined'); throw new Error(modelName + ' has not been defined');
} }
return this.modelManager.getDAO(daoName); return this.modelManager.getDAO(modelName);
}; };
/** /**
* Checks whether a model with the given name is defined * Checks whether a model with the given name is defined
* *
* @param {String} daoName The name of a model defined with Sequelize.define * @param {String} modelName The name of a model defined with Sequelize.define
* @return {Boolean} * @return {Boolean}
*/ */
Sequelize.prototype.isDefined = function(daoName) { Sequelize.prototype.isDefined = function(modelName) {
var daos = this.modelManager.daos; var daos = this.modelManager.daos;
return (daos.filter(function(dao) { return dao.name === daoName; }).length !== 0); return (daos.filter(function(dao) { return dao.name === modelName; }).length !== 0);
}; };
/** /**
...@@ -547,7 +547,7 @@ module.exports = (function() { ...@@ -547,7 +547,7 @@ module.exports = (function() {
} }
return when.then(function() { return when.then(function() {
var daos = [null]; var daos = [];
// Topologically sort by foreign key constraints to give us an appropriate // Topologically sort by foreign key constraints to give us an appropriate
// creation order // creation order
...@@ -558,9 +558,10 @@ module.exports = (function() { ...@@ -558,9 +558,10 @@ module.exports = (function() {
// DB should throw an SQL error if referencing inexistant table // DB should throw an SQL error if referencing inexistant table
} }
}); });
return Promise.reduce(daos, function(total, dao) { return Promise.reduce(daos, function(total, dao) {
return dao.sync(options); return dao.sync(options);
}); }, null);
}); });
}; };
...@@ -572,7 +573,7 @@ module.exports = (function() { ...@@ -572,7 +573,7 @@ module.exports = (function() {
* @return {Promise} * @return {Promise}
*/ */
Sequelize.prototype.drop = function(options) { Sequelize.prototype.drop = function(options) {
var daos = [null]; var daos = [];
this.modelManager.forEachDAO(function(dao) { this.modelManager.forEachDAO(function(dao) {
if (dao) { if (dao) {
...@@ -582,7 +583,7 @@ module.exports = (function() { ...@@ -582,7 +583,7 @@ module.exports = (function() {
return Promise.reduce(daos, function(total, dao) { return Promise.reduce(daos, function(total, dao) {
return dao.drop(options); return dao.drop(options);
}); }, null);
}; };
/** /**
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
"generic-pool": "2.0.4", "generic-pool": "2.0.4",
"sql": "~0.35.0", "sql": "~0.35.0",
"circular-json": "~0.1.5", "circular-json": "~0.1.5",
"sequelize-bluebird": "git://github.com/sequelize/bluebird.git", "sequelize-bluebird": "git://github.com/sequelize/bluebird.git#9df139af53c5d346ffd38df30fc9dc60c62a9c98",
"node-uuid": "~1.4.1" "node-uuid": "~1.4.1"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -632,7 +632,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -632,7 +632,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.User.create({ username: 'foo' }).success(function(user) { this.User.create({ username: 'foo' }).success(function(user) {
self.Task.create({ title: 'task1' }).success(function(task1) { self.Task.create({ title: 'task1' }).success(function(task1) {
self.Task.create({ title: 'task2' }).success(function(task2) { self.Task.create({ title: 'task2' }).success(function(task2) {
user.setTasks([task1, task2]).on('sql', spy).on('sql', _.after(2, function (sql) { // We don't care about SELECt, only UPDAET user.setTasks([task1, task2]).on('sql', spy).on('sql', _.after(2, function (sql) { // We don't care about SELECT, only UPDATE
expect(sql).to.have.string("UPDATE") expect(sql).to.have.string("UPDATE")
expect(sql).to.have.string("IN (1,2)") expect(sql).to.have.string("IN (1,2)")
})).success(function () { })).success(function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!