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

Commit a8f23bd8 by Jan Aagaard Meier

Merge master

2 parents 8b2c130e 620d8e77
......@@ -6,6 +6,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- `.success()`/`.done()` and any other non promise methods are now deprecated (we will keep the codebase around for a few versions though). on('sql') persists for debugging purposes.
- Model association calls (belongsTo/hasOne/hasMany) are no longer chainable. (this is to support being able to pass association references to include rather than model/as combinations)
- `QueryInterface` no longer emits global events. This means you can no longer do things like `QueryInterface.on('showAllSchemas', function ... `
- `define()` stores models in `sequelize.models` Object e.g. `sequelize.models.MyModel`
# v2.0.0-dev11
### Caution: This release contains many changes and is highly experimental
......
......@@ -290,7 +290,7 @@ module.exports = (function() {
return Utils._.template(query)(replacements)
},
deleteQuery: function(tableName, where, options, factory) {
deleteQuery: function(tableName, where, options, model) {
options = options || {}
tableName = Utils.removeTicks(this.quoteTable(tableName), '"')
......@@ -305,8 +305,8 @@ module.exports = (function() {
primaryKeys[tableName] = primaryKeys[tableName] || [];
if (!!factory && primaryKeys[tableName].length < 1) {
primaryKeys[tableName] = Object.keys(factory.primaryKeys)
if (!!model && primaryKeys[tableName].length < 1) {
primaryKeys[tableName] = Object.keys(model.primaryKeys)
}
var query = "DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
......
......@@ -9,6 +9,7 @@ module.exports = (function() {
ModelManager.prototype.addDAO = function(dao) {
this.daos.push(dao)
this.sequelize.models[dao.name] = dao
return dao
}
......@@ -17,6 +18,7 @@ module.exports = (function() {
this.daos = this.daos.filter(function(_dao) {
return _dao.name != dao.name
})
delete this.sequelize.models[dao.name]
}
ModelManager.prototype.getDAO = function(daoName, options) {
......
......@@ -1278,10 +1278,10 @@ module.exports = (function() {
var attrValueHash = {}
attrValueHash[self._timestampAttributes.deletedAt] = Utils.now()
query = 'bulkUpdate'
args = [self.getTableName(), attrValueHash, where]
args = [self.getTableName(), attrValueHash, where, self]
} else {
query = 'bulkDelete'
args = [self.getTableName(), where, options]
args = [self.getTableName(), where, options, self]
}
var runQuery = function(err, records) {
......
......@@ -519,9 +519,9 @@ module.exports = (function() {
});
}
QueryInterface.prototype.bulkDelete = function(tableName, identifier, options) {
var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null}))
return this.sequelize.query(sql, null, options)
QueryInterface.prototype.bulkDelete = function(tableName, identifier, options, model) {
var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null}), model)
return this.sequelize.query(sql, null, options)
}
QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) {
......
......@@ -162,6 +162,7 @@ module.exports = (function() {
} catch(err) {
throw new Error("The dialect " + this.getDialect() + " is not supported.")
}
this.models = {}
this.modelManager = this.daoFactoryManager = new ModelManager(this)
this.transactionManager = new TransactionManager(this)
......
......@@ -1120,6 +1120,47 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(model.options.uniqueKeys[fk].fields).to.deep.equal([ 'TaskId', 'UserId' ])
})
})
describe('without sync', function() {
beforeEach(function(done) {
var self = this
self.sequelize.queryInterface.createTable('users',{ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true } , username: DataTypes.STRING, createdAt: DataTypes.DATE, updatedAt: DataTypes.DATE }).success(function() {
self.sequelize.queryInterface.createTable('tasks',{ id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, title: DataTypes.STRING, createdAt: DataTypes.DATE, updatedAt: DataTypes.DATE }).success(function() {
self.sequelize.queryInterface.createTable('users_tasks',{ TaskId: DataTypes.INTEGER, UserId: DataTypes.INTEGER, createdAt: DataTypes.DATE, updatedAt: DataTypes.DATE }).success(function() {
done();
})
})
})
})
it('removes all associations', function(done) {
var self = this;
this.UsersTasks = this.sequelize.define('UsersTasks', {}, { tableName: 'users_tasks' });
self.User.hasMany(self.Task, { through: this.UsersTasks })
self.Task.hasMany(self.User, { through: this.UsersTasks })
expect(Object.keys(self.UsersTasks.primaryKeys)).to.deep.equal(['TaskId', 'UserId'])
self.User.create({username: 'foo'}).success(function(user) {
self.Task.create({title: 'foo'}).success(function(task) {
user.addTask(task).success(function(){
user.setTasks(null).success(function(result) {
expect(result).to.be.ok
done()
}).error(function(error) {
console.log(error);
expect(false).to.be.ok
done()
})
})
})
})
})
})
})
describe('through', function () {
......
......@@ -417,6 +417,13 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
done()
})
it("adds a new dao to sequelize.models", function(done) {
expect(this.sequelize.models.bar).to.equal(undefined)
var Bar = this.sequelize.define('bar', { title: DataTypes.STRING })
expect(this.sequelize.models.bar).to.equal(Bar)
done()
})
it("overwrites global options", function(done) {
var sequelize = Support.createSequelizeInstance({ define: { collate: 'utf8_general_ci' } })
var DAO = sequelize.define('foo', {bar: DataTypes.STRING}, {collate: 'utf8_bin'})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!