Navigation Menu

Skip to content
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
Closed

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

ggarek opened this issue Sep 23, 2014 · 2 comments
Labels
type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@ggarek
Copy link
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 Associations remove[AS][plural] Feature: Associations remove[AS][plural] Sep 23, 2014
@mickhansen mickhansen added the type: feature For issues and PRs. For new features. Never breaking changes. label Sep 24, 2014
@mickhansen
Copy link
Contributor

Agreed, that would be usefull.

simong added a commit to simong/sequelize that referenced this issue Nov 10, 2014
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
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
#2338 - Associations remove[AS][plural]
vpontis added a commit to vpontis/sequelize that referenced this issue Nov 11, 2014
* 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
Copy link
Member

Pr merged, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

No branches or pull requests

3 participants