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

Commit 83381e51 by Jan Aagaard Meier

Merge pull request #3964 from jrmurad/master

handle hasOne onDelete cascade when no associate
2 parents 9f4102b3 0c4ddcd8
......@@ -648,6 +648,11 @@ QueryInterface.prototype.delete = function(instance, tableName, identifier, opti
transaction: options.transaction,
logging: options.logging
}).then(function (instances) {
// Check for hasOne relationship with non-existing associate ("has zero")
if (!instances) {
return Promise.resolve();
}
if (!Array.isArray(instances)) instances = [instances];
return Promise.each(instances, function (instance) {
......
......@@ -381,6 +381,21 @@ describe(Support.getTestDialectTeaser('HasOne'), function() {
});
});
it('works when cascading a delete with hooks but there is no associate (i.e. "has zero")', function() {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING });
User.hasOne(Task, {onDelete: 'cascade', hooks: true});
return User.sync({ force: true }).then(function() {
return Task.sync({ force: true }).then(function() {
return User.create({ username: 'foo' }).then(function(user) {
return user.destroy();
});
});
});
});
// NOTE: mssql does not support changing an autoincrement primary key
if (Support.getTestDialect() !== 'mssql') {
it('can cascade updates', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!