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

Commit d0453674 by Mick Hansen

fix(Model): add support for destroys on models without primary keys, fixes #2561

1 parent 5c5cb18a
...@@ -440,7 +440,11 @@ module.exports = (function() { ...@@ -440,7 +440,11 @@ module.exports = (function() {
primaryKeys[tableName] = Object.keys(model.primaryKeys); primaryKeys[tableName] = Object.keys(model.primaryKeys);
} }
query = 'DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)'; if (options.limit) {
query = 'DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)';
} else {
query = 'DELETE FROM <%= table %> WHERE <%= where %>';
}
var pks; var pks;
if (primaryKeys[tableName] && primaryKeys[tableName].length > 0) { if (primaryKeys[tableName] && primaryKeys[tableName].length > 0) {
......
...@@ -1086,6 +1086,33 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1086,6 +1086,33 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('works without a primary key', function () {
var Log = this.sequelize.define('Log', {
client_id: DataTypes.INTEGER,
content: DataTypes.TEXT,
timestamp: DataTypes.DATE
});
Log.removeAttribute('id');
return Log.sync({force: true}).then(function () {
return Log.create({
client_id: 13,
content: 'Error!',
timestamp: new Date()
});
}).then(function () {
return Log.destroy({
where: {
client_id: 13
}
});
}).then(function () {
return Log.findAll().then(function (logs) {
expect(logs.length).to.equal(0);
});
});
});
it('supports .field', function () { it('supports .field', function () {
var UserProject = this.sequelize.define('UserProject', { var UserProject = this.sequelize.define('UserProject', {
userId: { userId: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!