Ember Data 3.24 ignoring query options

I posted this to Ember Discord, as well; in the #help channel.

Hello everyone :wave: I think I have an ember data issue, but I’m not 100% sure.

// queryParameters = {
//   page: {
//     number: 1,
//     size: 10
//   }
// }
const records = yield parent.query("child", queryParameters);

// GET /api/parent/:id/child?page[number]=1&page[size]=10

// queryParameters = {
//   page: {
//     number: 2,
//     size: 10
//   }
// }
const records = yield parent.query("child", queryParameters);

// GET child/:id <- was previously loaded; new query params ignored

I’m using Ember 3.24. This works as expected in Ember 2.18. I bring that up because I’m trying to upgrade our application.

How can I debug this? How can I make the 2nd, and subsequent requests go all the way to the back-end?

This query is inside a function that is used to populate an ember-light-table component. I’ll try to provide more information if requested. Thanks, in advance, for any assistance.

what is parent in this context? are you using any other addons or custom code to provide “nested” queries?

1 Like

parent is an Ember Model. I need to obfuscate code because the application isn’t open sourced. I should have used book and pages to represent parent and children.

Dang! We are using another addon:

export default Model.extend(HasManyQuery.ModelMixin, {

I can start looking there! I didn’t even think about it until I wanted to share a bit of book's implementation.

I need to see if I updated it, or not, because of the upgrade. And if it works with Ember 3.24.

Thanks! :heart:

That is definitely where I would start. It kinda seems like it might be skipping the “nested” query thing and falling back to a standard store.query or findRecord or something. Good luck!

1 Like

Following up to close the loop, and, if possible, get additional guidance.

The issue is the ember-data-has-many-query addon. While it appears abandoned, it also stopped working ‘out of the box’ after Ember Data 3.14.

It’s trying to make querying nested resources more convenient. We are trying to use it to support paged requests in an ‘infinite scroll’ implementation.

Unfortunately I’m not well-versed in Ember Data, or Javascript for that matter, so I’m unable to completely ditch the addon (like I should).

We have a JSONAPI Rails back-end. And it can support a request in the shape of:

GET /books/1/pages?page[number]=1&page[size]=10
GET /books/1/pages?page[number]=2&page[size]=10

Via the addon we used to be do the following:

const records = yield book.query('pages', { page: { number: 1, size: 10 } } )

(yes, we’re using ember-concurrency too)

How can I do this in plain ol’ Ember Data?

In stepping through the code (actually a ton of console.log statements) I believe the issue has to do with HasManyReference#reload

This causes a request to the specified relationship link or reloads all items currently in the relationship.

I’m seeing subsequent calls to #reload exhibit the latter behavior even though the query parameters are different.

Thanks for any help, in advance :smiley:

This PR linked from the issue that you commented on seems to have some sort of fix that may help. You could your own fork of that fork or your own fork with that change re-implemented. In the long term you may want to try to build something of your own since maintaining forks is not great, but that may get you unblocked in the meantime? Hopefully that actually works.

If not you could try essentially re-implementing the addon (but probably a simpler version). Most of the code is in two mixins (Adapter and Model) and instead of using mixins you could use a base class that uses your version of this code and extend all your adapters/models from it. That might not be super horrible if you start off with mostly the same code and go from there :thinking:

1 Like

First, my apologies for my delayed reply. Second, more importantly, thank you very much for your guidance.

However, the fix didn’t work. For this part of our application I’m electing to go a different route. I feel there are several obstacles working against me here:

  1. My general lack of Ember knowledge. While I don’t necessarily have to know the internals, I feel a good understanding of the plumbing would be beneficial. I do not have that. The documentation for HasManyReferenc#load and HasManyReference#reload leads me to believe I’m missing something critical because I’m not able to make the PR work…at all.
  2. My general lack of Javascript expertise. Truly this language is giving me a round for my money. It’s not my first language as I generally spend most of my time in Ruby. I feel, much like I do about Ember, I need a bit more experience before I feel comfortable in this new world. Promises hurt my head.
  3. Self-imposed deadlines. I’m delaying the rollout of this major upgrade because of this one issue, albeit an important one. The changes are starting to pile up and I need move on.

What’s odd is the Rails JSONAPI Server is sending pagination links in the response. If only Ember could process those because I already have a ‘next’ link, etc. However, for this piece of the application I will not be using ember-data-has-many-query and will be going with a “pagination” approach.

Thanks again!

P.S. Why are nested resources so difficult in Ember?