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

A bidirectional relationship parent.children becomes hasLoaded: true when a child that references the parent is pushed to the store #5211

Closed
lolmaus opened this issue Oct 6, 2017 · 7 comments · Fixed by #5410

Comments

@lolmaus
Copy link
Contributor

lolmaus commented Oct 6, 2017

Affected versions

Ember Data 2.14+. This includes current stable Ember Data 2.16.1.

Steps to reproduce

Given two models:

// parent
export default Model.extend({
  children: hasMany('child')
});
// child
export default Model.extend({
  parent: belongsTo('parent')
});

Push two records into the store:

    const parent = store.push({
      data: {
        id: '1',
        type: 'parent',
        
        relationships: {
          children: {
            links: {
              "self": "https://example.com/parents/1/relationships/children",
              "related": "https://example.com/parents/1/children"
            }
          }
        }
      }
    })

    const child = store.push({
      data: {
        id: '1',
        type: 'child',
        relationships: {
          parent: {
            data: {
              id: '1',
              type: 'parent'
            }
          }
        }
      }
    })

Expected behavior (Ember Data 2.13 and below work correctly)

The parent.children relationship is not considered loaded:

parent.hasMany('children').hasManyRelationship.hasLoaded // => false

When you do parent.get('children'), a network request is made.

Actual behavior (Ember Data 2.14 and above)

The parent.children relationship is considered loaded:

parent.hasMany('children').hasManyRelationship.hasLoaded // => true

When you do parent.get('children'), a network request is not made, which breaks our app in many ways.

Reproduction

https://ember-twiddle.com/3331c5dfc361920818fa3325842f5b3e?openFiles=controllers.application.js%2C (see console output, then try switching to 2.12.0 in twiddle.json)

Credit

This bug has been discovered by @vvainio.

@lolmaus
Copy link
Contributor Author

lolmaus commented Oct 6, 2017

This happens not only after a push. You can findRecord or query for a child, and if it references a parent, the parent will start thinking that it has only one child.

@lolmaus
Copy link
Contributor Author

lolmaus commented Oct 6, 2017

This one seems to be either related or duplicate: #5209.

@vvainio
Copy link

vvainio commented Oct 6, 2017

Here's another Twiddle demonstrating this issue. In our use-case, we are fetching some data in the route's model hook, and then side loading the rest. This pattern has worked at least up until 2.12.2.

https://ember-twiddle.com/45d37cc9b2525b32f3cd6dbda1c96ecf?fileTreeShown=false&numColumns=2&openFiles=routes.application.js%2Ctemplates.application.hbs

@BryanCrotaz
Copy link
Contributor

BryanCrotaz commented Nov 12, 2017

#5209 isn't the same issue - it only happens when inverse on one end is null (and I just fixed it with a PR)

@BryanCrotaz
Copy link
Contributor

I have a failing test for this one - I'll try and fix tomorrow.

@BryanCrotaz
Copy link
Contributor

BryanCrotaz commented Nov 12, 2017

Fixed in PR #5257
@igorT @stefanpenner Can we get this reviewed and merged quickly? It's a major bug that changes client side data if using links.

@bmac
Copy link
Member

bmac commented Mar 5, 2018

I believe this has been resolved 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.

4 participants