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

Links related relationship on modelA nulls belongsTo on modelB #5209

Closed
DingoEatingFuzz opened this issue Oct 5, 2017 · 9 comments · Fixed by #5410
Closed

Links related relationship on modelA nulls belongsTo on modelB #5209

DingoEatingFuzz opened this issue Oct 5, 2017 · 9 comments · Fixed by #5410

Comments

@DingoEatingFuzz
Copy link
Contributor

Data Model

  1. modelA has a hasMany('modelB')
  2. modelB has a belongsTo('modelA')
  3. modelB payload looks like this: model_a_id: 'model-a-1'
  4. modelA payload does not include the set of modelB ids. Instead, it is related through a related link: /api/model-a/:id returns the model and /api/model-a/:id/model-b returns the set of related modelB.

Steps to reproduce

  1. Find a modelB
  2. Do not find the modelB's modelA
  3. Find modelB's modelA independently
  4. Observe that modelB.get('modelA') is a fulfilled promise with null for content

Expected result

modelB should maintain its relationship with modelA despite modelA being loaded with unknown IDs for its hasMany modelB.

Actual result

The relationship is null and the original ID from the payload is now lost.

Notes

This only happens in this order. If modelB's modelA is already loaded, it seems to be fine.

@pangratz
Copy link
Member

pangratz commented Oct 5, 2017

Can you update this ember-twiddle so it demonstrates the issue you're having? That would help greatly track down the issue your having! Thanks!

@lolmaus
Copy link
Contributor

lolmaus commented Oct 6, 2017

I've filed a very similar issue: #5211, it's either related or duplicated. I've provided a reproduction twiddle.

@williamhector
Copy link

Here is a twiddle that I believe is the same issue as the OP:
https://ember-twiddle.com/2cf56ec2cd082d5c5a109e51993de730?openFiles=adapters.organisation.js%2C

The application route loads a given user, loads a given organisation, then loads the user's organisation (should be the same as the given org).
The organisation's users relationship (adminUsers) is never loaded, so while it might be related, I believe it's not a duplicate.

If you omit the "links" from the payload in adapters/organisation.js, the issue doesn't occur.
Or, if you call user.get('organisation') before store.findRecord('organisation', id) in routes/application.js then the issue doesn't occur.

@BryanCrotaz
Copy link
Contributor

I can confirm this behaviour in a real world app

@BryanCrotaz
Copy link
Contributor

I'm working on a PR

@BryanCrotaz
Copy link
Contributor

BryanCrotaz commented Nov 11, 2017

I have a failing test based on @williamhector 's twiddle...
Inverse relationship must be null on the belongsto to break

@BryanCrotaz
Copy link
Contributor

BryanCrotaz commented Nov 12, 2017

Found the problem - the payload data is cached until you read the relationship. Because you've not defined the inverse on one side, the second one is stomping on it - we need to keep the two relationships separate when defining the second end of the relationship.
Working on it

@BryanCrotaz
Copy link
Contributor

Fixed in #5257

@bmac
Copy link
Member

bmac commented Mar 5, 2018

I believe this has been fixed by #5230. Feel free to reopen if it is still an issue.

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

Successfully merging a pull request may close this issue.

6 participants