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

Commit 0e9f5fcd by Mick Hansen

Merge pull request #2525 from vpontis/associating-sections-when-deletions

Breaking include on find when irrelevant columns in the join table
2 parents 5a900801 1982585a
Showing with 45 additions and 0 deletions
......@@ -1565,6 +1565,51 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
});
});
it('should correctly get associations even after a child instance is deleted', function() {
var self = this,
user, projects;
return this.sequelize.sync({logging: console.log}).then(function() {
return Promise.all([
self.User.create({name: 'Matt'}),
self.Project.create({name: 'Good Will Hunting'}),
self.Project.create({name: 'The Departed'})
]);
})
.spread(function (user, project1, project2) {
return user.addProjects([project1, project2]).return(user);
})
.then(function(user) {
return Promise.all([
user,
user.getProjects()
]);
})
.then(function(savedUser, savedProjects) {
var user = savedUser,
projects = savedProjects;
return Promise.all([
self.sequelize.query('alter table user_projects drop constraint user_projects_project_id_fkey;'),
self.sequelize.query('alter table user_projects drop constraint user_projects_user_id_fkey;')
])
})
.spread(function() {
var project = projects[0];
expect(project).to.be.defined;
return project.destroy().return(user);
})
.then(function(user) {
return self.User.find({
where: { id: user.id},
include: self.Project
});
})
.then(function(user) {
var projects = user.Projects;
var project = projects[0];
expect(project).to.be.defined;
});
});
it('should correctly get associations when doubly linked', function() {
var self = this;
return this.sequelize.sync({force: true}).then(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!