-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Feature: Associations remove[AS][plural] #2338
Copy link
Copy link
Closed
Labels
type: featureDEPRECATED: replace with the "feature" issue typeDEPRECATED: replace with the "feature" issue type
Description
Sequelize version: 2.0.0-rc1
What about providing a method to remove associations, when array of association ids is given?
Models given:
...
User.hasMany(Project)
Project.hasMany(User)
...What i want to do on a hunch:
var user = ...
var toRemove = [1,2,3]; // e.g. got from http request
user.removeProjects(toRemove).complete(...);But, the only option i have:
var user = ...
var allUserProjectIds = [1,2,3,4,5]; // ! excess db query
var toRemove = [1,2,3]; // e.g. got from http request
var updatedUserProjecIds = difference(allUserProjectIds, toRemove); // [4,5]
user.setProjects(updatedUserProjecIds).complete(...);If i am not mistaken currently i can remove associations this way:
- user.setProjects([]) - Remove all associations
- user.removeProject(project) ** - Remove single association
But i really need to remove a range of associations!
Thank you!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: featureDEPRECATED: replace with the "feature" issue typeDEPRECATED: replace with the "feature" issue type