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

Commit 54655ab2 by Mick Hansen

fix(model/destroy): fix model.destroy() where .sync() hasn't been called (closes #1730)

1 parent 11dba9ec
...@@ -290,7 +290,7 @@ module.exports = (function() { ...@@ -290,7 +290,7 @@ module.exports = (function() {
return Utils._.template(query)(replacements) return Utils._.template(query)(replacements)
}, },
deleteQuery: function(tableName, where, options, factory) { deleteQuery: function(tableName, where, options, model) {
options = options || {} options = options || {}
tableName = Utils.removeTicks(this.quoteTable(tableName), '"') tableName = Utils.removeTicks(this.quoteTable(tableName), '"')
...@@ -305,8 +305,8 @@ module.exports = (function() { ...@@ -305,8 +305,8 @@ module.exports = (function() {
primaryKeys[tableName] = primaryKeys[tableName] || []; primaryKeys[tableName] = primaryKeys[tableName] || [];
if (!!factory && primaryKeys[tableName].length < 1) { if (!!model && primaryKeys[tableName].length < 1) {
primaryKeys[tableName] = Object.keys(factory.primaryKeys) primaryKeys[tableName] = Object.keys(model.primaryKeys)
} }
var query = "DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)" var query = "DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
......
...@@ -1278,10 +1278,10 @@ module.exports = (function() { ...@@ -1278,10 +1278,10 @@ module.exports = (function() {
var attrValueHash = {} var attrValueHash = {}
attrValueHash[self._timestampAttributes.deletedAt] = Utils.now() attrValueHash[self._timestampAttributes.deletedAt] = Utils.now()
query = 'bulkUpdate' query = 'bulkUpdate'
args = [self.getTableName(), attrValueHash, where] args = [self.getTableName(), attrValueHash, where, self]
} else { } else {
query = 'bulkDelete' query = 'bulkDelete'
args = [self.getTableName(), where, options] args = [self.getTableName(), where, options, self]
} }
var runQuery = function(err, records) { var runQuery = function(err, records) {
......
...@@ -565,8 +565,8 @@ module.exports = (function() { ...@@ -565,8 +565,8 @@ module.exports = (function() {
}); });
} }
QueryInterface.prototype.bulkDelete = function(tableName, identifier, options) { QueryInterface.prototype.bulkDelete = function(tableName, identifier, options, model) {
var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null})) var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null}), model)
return this.queryAndEmit([sql, null, options], 'bulkDelete', options) return this.queryAndEmit([sql, null, options], 'bulkDelete', options)
} }
......
...@@ -1121,7 +1121,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1121,7 +1121,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) })
}) })
describe('no run sync', function() { describe('without sync', function() {
beforeEach(function(done) { beforeEach(function(done) {
var self = this var self = this
...@@ -1139,8 +1139,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1139,8 +1139,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var self = this; var self = this;
this.UsersTasks = this.sequelize.define('UsersTasks', {}, { tableName: 'users_tasks' }); this.UsersTasks = this.sequelize.define('UsersTasks', {}, { tableName: 'users_tasks' });
self.User.hasMany(self.Task, { joinTableName: this.UsersTasks }) self.User.hasMany(self.Task, { through: this.UsersTasks })
self.Task.hasMany(self.User, { joinTableName: this.UsersTasks }) self.Task.hasMany(self.User, { through: this.UsersTasks })
expect(Object.keys(self.UsersTasks.primaryKeys)).to.deep.equal(['TaskId', 'UserId']) expect(Object.keys(self.UsersTasks.primaryKeys)).to.deep.equal(['TaskId', 'UserId'])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!