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

Update Many-To-Many-Through Relationship not dropping associations #5271

Closed
chase-bleyl opened this issue Feb 22, 2017 · 4 comments
Closed

Comments

@chase-bleyl
Copy link

Waterline version: 0.11.9
Node version: 6.9.4
NPM version: 3.10.10
Operating system: macOS Sierra


I am having an issue with the many-to-many through association where I can't update properly. On update, it doesn't seem to be dropping the associations before writing the new ones. Thus, update() won't remove associations that aren't valid anymore.

I have recreated this issue at https://github.com/chase-bleyl/test-update.

I have three models:

  • Assignment
  • AssignmentTag
  • Tag

In /api/controllers/AssignmentController I have the update function. I will pass in an array of Tag ids that omits some IDs that are present and adds some new ones. The new IDs are added correctly, but the old IDs aren't removed, which leads me to believe that the associations aren't dropping properly before the add.

What is confusing is that I can read/write fine from these associations. I can populate the Tag objects from the Assignment, and the .update() adds the new tags to the Assignment object fine.

Any idea what I am doing wrong here?

@particlebanana
Copy link
Contributor

Hey @chase-bleyl the nested association stuff is pretty wonky in Waterline 0.11. In the latest version that will ship with Sails v1 we went ahead and removed the nested "syncing" and added methods for adding, removing, and replacing associations.

We are working full speed to try and get that version out the door but I'll take a look when I get a spare minute and see if I can quickly track it down. All of these models are using the same database correct?

@chase-bleyl
Copy link
Author

Thanks @particlebanana for addressing this. You are correct - all these models are hitting the same DB.

@particlebanana
Copy link
Contributor

Alright @chase-bleyl it should be all patched up in Waterline 0.11.10. If you re-install Sails it should pick it up.

@chase-bleyl
Copy link
Author

I just tested and update on through associations seems to be working fine. Thank you @particlebanana !

@raqem raqem transferred this issue from balderdashy/waterline May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants