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

Commit e7521c4d by Mick Hansen

Test and fix for removeHasManyDoubleLinkedAssociation

1 parent ba58986d
......@@ -121,9 +121,15 @@ module.exports = (function() {
if (!newObj) {
obsoleteAssociations.push(old)
} else if (Object(targetAssociation.through) === targetAssociation.through) {
var throughAttributes = newObj[self.association.through.name];
// Quick-fix for subtle bug when using existing objects that might have the through model attached (not as an attribute object)
if (throughAttributes instanceof self.association.through.DAO) {
throughAttributes = {};
}
var changedAssociation = {
where: {},
attributes: Utils._.defaults({}, newObj[self.association.through.name], defaultAttributes)
attributes: Utils._.defaults({}, throughAttributes, defaultAttributes)
}
changedAssociation.where[self.association.identifier] = self.instance[self.association.identifier] || self.instance.id
......
......@@ -886,6 +886,40 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
describe('removing from the join table', function () {
it('should remove a single entry without any attributes (and timestamps off) on the through model', function (done) {
var Worker = this.sequelize.define('Worker', {}, {timestamps: false})
, Task = this.sequelize.define('Task', {}, {timestamps: false})
, WorkerTasks = this.sequelize.define('WorkerTasks', {}, {timestamps: false})
Worker.hasMany(Task, { through: WorkerTasks })
Task.hasMany(Worker, { through: WorkerTasks })
this.sequelize.sync().done(function(err) {
expect(err).not.to.be.ok
Worker.create().done(function (err, worker) {
expect(err).not.to.be.ok
Task.bulkCreate([{}, {}]).done(function (err) {
expect(err).not.to.be.ok
Task.findAll().done(function (err, tasks) {
expect(err).not.to.be.ok
worker.setTasks(tasks).done(function (err) {
worker.removeTask(tasks[0]).done(function (err) {
expect(err).not.to.be.ok
worker.getTasks().done(function (err, tasks) {
expect(tasks.length).to.equal(1)
done()
})
})
})
})
})
})
})
})
})
})
describe('belongsTo and hasMany at once', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!