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

unloadRecord after v2.12 #5328

Closed
Vincz opened this issue Jan 18, 2018 · 10 comments
Closed

unloadRecord after v2.12 #5328

Vincz opened this issue Jan 18, 2018 · 10 comments

Comments

@Vincz
Copy link

Vincz commented Jan 18, 2018

Hey :)

I have this simple piece of code (removing record from the store while notified by a websocket).

handleRemove: function(content) {
        var store = this.get("store");
        for (var model in content) {
            if (!this.get("ignoredModels").includes(model)) {
                var modelId = content[model]["id"];
                var object = store.peekRecord(store.convert(model), modelId);
                if (object) {
                    object.unloadRecord();
                }
            }
        }
    }

In ember-data 2.12 everything works as expected.
But after this version, I'm unable to track the origin (if someone know how to do it ?), but the store tries to re-fetch some unloaded models (and fail with a 404 from the server).
I'm also encoutering sometimes the Cannot read property 'eachAttribute' of null error that others seems to have on unload.

@henrymazza
Copy link

henrymazza commented Jan 25, 2018

I worked around it with

   record.get('_internalModel').transitionTo('deleted.saved');

right after before unloading the model. All the null values vanished from the ManyArrays, RecordArrays, etc. Don’t forget to wrap in a runloop. Needs more tests, btw.

@bastimeyer
Copy link

I've just tried upgrading to ED 3.0.1 and am still experiencing this issue.
See this simple test: https://gist.github.com/bastimeyer/ecb84112ba24082dfa58fdd3596ef978

@runspired
Copy link
Contributor

unloadRecord should not be use for client-side delete. I would recommend building a solution overtop of deleteRecord instead.

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 19, 2018

@runspired I thought the recent work by @hjdivad around unloadRecord was to bring back this client-side delete. I'm just confused now.

@runspired
Copy link
Contributor

@sly7-7 it brought it back for a small subset of cases where it could work.

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 19, 2018

In that case, I think I must rework my client-side delete process of the object in my app. But won't deleteRecord let some "zombies" records, and so my application will leak ?

@JonathanBristow
Copy link

If we shouldn't use unloadRecord how would you advise removing a record from the store?
The record I'm working with is loaded as part of a hasMany relationship.

@henrymazza
Copy link

henrymazza commented Mar 23, 2018 via email

@runspired
Copy link
Contributor

@JonathanBristow it's complicated :( I'll be looking into building an addon to experiment with this soon while we wait for json-api operations to finalize to give us a public api spec to follow.

@runspired
Copy link
Contributor

A better discussion of the true heart of this issue is in #5424

Closing in favor of that ticket.

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

No branches or pull requests

6 participants