Skip to content

Feature: Associations remove[AS][plural] #2338

@ggarek

Description

@ggarek

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureDEPRECATED: replace with the "feature" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions