New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ggarek opened this Issue Sep 23, 2014 · 2 comments

Comments

3 participants
@ggarek
Contributor

ggarek commented Sep 23, 2014

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!

@ggarek ggarek changed the title from Associations remove[AS][plural] to Feature: Associations remove[AS][plural] Sep 23, 2014

@mickhansen mickhansen added the feature label Sep 24, 2014

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Sep 24, 2014

Agreed, that would be usefull.

simong added a commit to simong/sequelize that referenced this issue Nov 10, 2014

sequelize#2338 - Remove multiple associations
This commits adds a function on has-many instances of the form:
remove[AS][Plural]

simong added a commit to simong/sequelize that referenced this issue Nov 10, 2014

sequelize#2338 - Remove multiple associations
This commits adds a function on has-many instances of the form:
remove[AS][Plural]

simong added a commit to simong/sequelize that referenced this issue Nov 10, 2014

mickhansen added a commit that referenced this issue Nov 10, 2014

Merge pull request #2560 from simong/remove-multiple
#2338 - Associations remove[AS][plural]

vpontis added a commit to vpontis/sequelize that referenced this issue Nov 11, 2014

Merge branch 'master' into associating-sections-when-deletions
* master:
  Allow removing has-many associations by id
  Update README.md
  sequelize#2338 - Associations remove[AS][plural]
  Use the new beta build env on Travis
  Text fix
  More promises
  Promisify tests
  Remove unnecssarily asynchronous tests
  Update changelog with BC breaking hstore change
  Update json test expectation
  Merge fix
  Update pg-hstore
  Removed no longer supported nested hstore objects from tests. Improved hstore array handling.
  Use pg-hstore for hstore parsing
  Hstore empty string tests
@janmeier

This comment has been minimized.

Member

janmeier commented Jan 14, 2015

Pr merged, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment