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

Model.update broken for many-to-many relations #23

Closed
markerikson opened this issue Jun 5, 2016 · 4 comments
Closed

Model.update broken for many-to-many relations #23

markerikson opened this issue Jun 5, 2016 · 4 comments

Comments

@markerikson
Copy link
Collaborator

Model.update() checks to see if a given field to update is a many-to-many relation. If so, it tries to use a function called arrayDiffActions() to determine which IDs have been added or removed from the existing list. It's trying to import that function from utils.js, but the function no longer exists. Looks like it was removed in commit 560c81d on May 9, while working on adding use of the immutable ops lib.

As a result, Model.update() currently breaks due to the undefined function reference.

@tommikaikkonen
Copy link
Collaborator

Sorry for the delay here -- was on a trip for a couple of weeks.

Looks like I didn't have a test in place to catch that regression. Wrote test to catch regression and fixed it in 72daf37, will make a new release later today.

@markerikson
Copy link
Collaborator Author

Sure. In the meantime, I wrote a utility function for myself that does fairly similar behavior.

@carlesnunez
Copy link

Can u give me more info about that?

I am trying to update a model with a many relationship and im getting with that error:
Possible Unhandled Promise Rejection (id: 0):
Tried to add already existing XXX id(s)

@carlesnunez
Copy link

carlesnunez commented Mar 23, 2017

Self response:

If we go to the file Model.js we can see in the line 425

if (idsToAdd.length > 0) {

That is causing a bug on the update of an empty many relationship array. Is not deleting any relationship but instead is adding links to relationships. That is causing a problem on the update process throwing the error that I pasted before

We can avoid that changing the line to that:

if (idsToAdd.length > 0 && currentIds.length > 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants