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

Relationship data lost when a record is unloaded #3020

Closed
aquamme opened this issue Apr 22, 2015 · 6 comments
Closed

Relationship data lost when a record is unloaded #3020

aquamme opened this issue Apr 22, 2015 · 6 comments

Comments

@aquamme
Copy link
Contributor

aquamme commented Apr 22, 2015

Assume that 'Car' hasMany 'Part', and 'Part' hasMany 'Car'. If a part is unloaded, then loaded again into the store, the information about its relationship to car is lost. I would expect a record's relationship data to survive as long as one of the records in the relationship still exists in the store (at least in the case where the relationship is declared on both models). Here is a jsbin illustrating the issue. I can PR a failing test if this is behavior that should be changed.

@bmac
Copy link
Member

bmac commented May 6, 2015

@igorT will your work on the https://github.com/emberjs/data/tree/references have any impact on this issue?

@aquamme
Copy link
Contributor Author

aquamme commented Jun 23, 2015

Looks like this issue will be covered by #3296

@workmanw
Copy link

I too have been experiencing this issue. Actually, it often results in a crash when the 'part' is later reloaded into the store. The stack looks like:

    at new Error (native)
    at Error.EmberError (https://localhost:4200/assets/vendor.js:26216:21)
    at Object._emberMetalCore.default.assert (https://localhost:4200/assets/vendor.js:14935:13)
    at Object.set (https://localhost:4200/assets/vendor.js:30394:32)
    at exports.default._emberMetalMixin.Mixin.create.set (https://localhost:4200/assets/vendor.js:46190:31)
    at Ember.Object.extend.flushCanonical (https://localhost:4200/assets/vendor.js:79683:14)
    at ember$data$lib$system$relationships$state$has$many$$ManyRelationship.flushCanonical (https://localhost:4200/assets/vendor.js:80009:22)
    at Queue.invoke (https://localhost:4200/assets/vendor.js:10439:16)
    at Object.Queue.flush (https://localhost:4200/assets/vendor.js:10503:11)
    at Object.DeferredActionQueues.flush (https://localhost:4200/assets/vendor.js:10304:17)

In my case, we unload some data as the user is exiting routes. If they return to the same route, as the data is being pushed back into the store, flushCanonical ends up called on an unloaded record.

Did you ever find a workaround, other than not unloading?

@wecc
Copy link
Contributor

wecc commented Oct 22, 2016

I'm still able to reproduce this using Ember release and Ember Data canary, see https://ember-twiddle.com/1960841c246dad18f83389a0b1e5de18

This should be fixed by #4593

@hjdivad
Copy link
Member

hjdivad commented Oct 22, 2016

@wecc #4593 should fix this issue although it doesn't completely fix the state of relationships on unload.

But for unload followed by pushPayload it does. see this test

@runspired
Copy link
Contributor

If this is still a problem we should open a new issue. The recent links refactor give me much more confidence that we don't lose information on unload; however, if there is still a case where we do it will be relatively simple to resolve at this point with the new flags that are in place for tracking relationship state internally.

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