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

Commit 84f80481 by u9r52sld Committed by Sushant

fix(belongsToMany): association.add returns array of array of through records (#9700)

1 parent f81e1385
...@@ -674,6 +674,7 @@ class BelongsToMany extends Association { ...@@ -674,6 +674,7 @@ class BelongsToMany extends Association {
return association.through.model.findAll(_.defaults({where, raw: true}, options)) return association.through.model.findAll(_.defaults({where, raw: true}, options))
.then(currentRows => updateAssociations(currentRows)) .then(currentRows => updateAssociations(currentRows))
.spread(associations => associations)
.catch(error => { .catch(error => {
if (error instanceof EmptyResultError) return updateAssociations(); if (error instanceof EmptyResultError) return updateAssociations();
throw error; throw error;
......
...@@ -1056,6 +1056,27 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1056,6 +1056,27 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect(tasks[0].title).to.equal('get started'); expect(tasks[0].title).to.equal('get started');
}); });
}); });
it('should returns array of intermediate table', function() {
const User = this.sequelize.define('User');
const Task = this.sequelize.define('Task');
const UserTask = this.sequelize.define('UserTask');
User.belongsToMany(Task, { through: UserTask });
Task.belongsToMany(User, { through: UserTask });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.all([
User.create(),
Task.create()
]).spread((user, task) => {
return user.addTask(task);
}).then(userTasks => {
expect(userTasks).to.be.an('array').that.has.a.lengthOf(1);
expect(userTasks[0]).to.be.an.instanceOf(UserTask);
});
});
});
}); });
describe('addMultipleAssociations', () => { describe('addMultipleAssociations', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!