If not unloadAll or unloadRecord, what can I do/use?

Sorry for the click-bait title but I’m not sure how else to frame my question/request.

First: I’m using: ember-cli: 2.18.2 calling a Rails JSONAPI-compliant backend. This project is generally a rewrite of the frontend. The backend process have not been altered but to comply with a JSONAPI Responses. Rewriting those processes is out of scope, completely.

Second: I’m struggling a bit and I was wondering if folks could lend a hand, or some guidance/advice. I think I’m struggling with Ember Data’s “stickiness” (my term).

We have a process that creates and destroys database records in the backend. These records are requested for display and processing. This is done by requesting this process be run via a user-initiated action (i.e. they click a button). After the user has processed this data, making adjustments, if you will, they can request this process be run again.

Like I mentioned: the backend process destroys the previously created records, creates new ones, and returns the new records.

I now have old models in the store that are getting counted when they shouldn’t.

I’ve tried using unloadAll('<type>') and unloadRecord() because I’m trying to get the old models out of the store. However, there is a fetch involved and for the old records they are indeed gone; a 404 is returned, rightfully.

If I’m on the wrong path, please let me know with some gentle redirection. What should/could I be doing instead?

Ideally, here’s what I would like to happen: Just before the process is requested I remove the old models from the store, request the process, and then load up the new models.

I can try to provide additional details if requested. Suffice it to say, I’m banging my head against the wall here.

Thank you for your time.

1 Like

Posting a follow-up here, to close the loop.

So I "Kobayashi Maru"ed this challenge; I “changed the test” such that I removed Ember Data from the solution.

I dropped down to fetching and processing the raw JSON API response, and didn’t store anything in the data store.

Thank you for your time.

1 Like

Actually I think your solution is correct. Ember Data is not a good fit for data that isn’t persisted. Using plain fetch for these cases is correct in my opinion. Doesn’t make much sense to force something into Ember Data models and client-side caching which doesn’t fit well. Authentication related data (login, session) is a common example of that one.

Ember Data has had some bugs around unloadRecord() and unloadAll(). They are fixed in latest version. Not sure if latest 2.18.x release is affected. Maybe that bugs were causing the issues you were facing.