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

2.14.7 regression store.query breaks some many2many relationships #5140

Closed
jrjohnson opened this issue Aug 19, 2017 · 4 comments
Closed

2.14.7 regression store.query breaks some many2many relationships #5140

jrjohnson opened this issue Aug 19, 2017 · 4 comments

Comments

@jrjohnson
Copy link
Contributor

jrjohnson commented Aug 19, 2017

This issues doesn't exist in 2.13.2 - 2.14.6, it appears for the first time in 2.14.7 and still exists in 2.15.0-beta.4.

Sorry for the meandering ticket and all the leaky domain stuff from using my own API, not really sure what details might be important here.

I'm doing some pre-loading of relationships in my router to save network requests. In my route I have:

afterModel(model) {
  return store.query('objective', {filters: {courses}});
}

Which loads all the objectives that would be loaded with a course.get('objectives'). The goal is for them to then be available in the store without needing to fetch each one individually.

This works as long as each objective returned only has a single course in its relationship like

{
  id: 1
  courses: [1]
}

but it seems to fail if there are more than one:

{
  id: 1
  courses: [1, 2]
}

The result ends up being that the loaded course model somehow gets confused and thinks it is only linked to some of the objectives. Operations like {{#each course.objective}} or {{course.objectives.length}} or even course.hasMany('objectives').ids() all provide incorrect data.

This only happens when the route is visited directly (by refreshing the page or typing in the URL). If a link-to is followed (even one that uses an id and not an object for the model then the relationships all load.

I've tried to create a small reproduction of this, unfortunately I couldn't make it work with ember-twiddle but I have breaking code here:

https://github.com/jrjohnson/reproduction-ember-data-query-does-not-update-store
and a running app example at:
https://grader-duck-81038.netlify.com/

I've created three routes:

  1. Working - no afterModel hook used, works fine
  2. Broken - afterModel hook used, breaks
  3. Working with fewer related items uses afterModel hook, but loads a different course object with objectives that are only related to itself.

(edited: added info that 2.15.0-beta.4 was tested)
(edited: I'm not sure where I got it wrong originally but this issues actually showed up in 2.14.7 for the first time.)

@sandstrom
Copy link
Contributor

sandstrom commented Aug 22, 2017

Does afterModel even fire when you visit from a link? I think it won't, and that's probably why it works in that case.

This isn't an answer to your issue, but if that's the case I'd amend the issue above to remove the section about link-to.


Have you verified that the payloads returned from the backend are identical in all cases?

@jrjohnson
Copy link
Contributor Author

Thanks @sandstrom,
afterModel is fired for every request (just verified to be sure), and i'm pretty sure that even model gets fired when you pass a model id and not a model object which is why I structured the link-to that way.

I have verified that payloads are identical where applicable, though the core of this issue is that calling store.query() breaks something. Since I don't call that in all of the working cases there is no payload to compare.

@jrjohnson jrjohnson changed the title 2.14 regression query() seems to break in many2many relationship 2.14 regression store.query breaks some many2many relationships Aug 22, 2017
@jrjohnson jrjohnson changed the title 2.14 regression store.query breaks some many2many relationships 2.14.7 regression store.query breaks some many2many relationships Aug 23, 2017
@jrjohnson
Copy link
Contributor Author

I believe this is caused by #5086 (git bisect FTW) which was a bugfix in itself added by @stefanpenner I'm going to see if I can understand it enough to put some tests or event a fix together.

@stefanpenner
Copy link
Member

fix has been backported, and will go out with: 2.14.11 + v2.15.0-beta.5

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.

3 participants