-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix client-side delete + resurrection #5249
Conversation
#5136 / #5137 are expecting This use case is supported per documentation via a client-side delete, ie
However, some client-side delete use cases require resurrection (ie client-side deleting the record and then pushing the same record back into the store and repopulating inverses). This behaviour was changed in #5058, which aimed to keep local state in relationships after record deletion |
537f4f8
to
882c1b3
Compare
@workmanw i believe I've captured your use case in public api in the test, but have also verified in your repo https://github.com/workmanw/unload-relationships-bug If you can confirm this solves your issue that would be great but in either case thanks for your diligence and patience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed \w @hjdivad, this LGTM.
Glad we can drop this extra complexity. |
I suspect I didn't add an adequate enough test for why that extra guard was needed. I'll dig in this morning. EDIT: (FTR I too am hoping we can drop the guard, I'm just suspicious because at the time I added it things broke without it). |
After reviewing the tests +1 LGTM |
Previously relationships were only cleared for new records. Now they are cleared for destroyed records as well, allowing destroyed records to be pushed back into the store and properly update their inverse relationships. This fixes the public API for client-side delete via an adapter, see #5136.
882c1b3
to
9e39629
Compare
@runspired the reason this doesn't regress the local-changes preservation is because it's captured by flushCanonical |
@hjdivad records in the TL;DR what I'm saying is:
|
So using this PR with the suggested changes for "client side delete" and "unloading" does work around the issues of #5136. comment.destroyRecord({ adapterOptions: { clientSideDelete: true } }).then(() => {
comment.unloadRecord();
}); In my application, we have a base model, so I'd probably just create a utility function for this behavior. E.g. |
this may possibly fix the issue we've been having which I submitted here... #5237 |
@workmanw we're going to restore the previous semantics of Your suggestion of having some kind of "skip adapter" functionality is a good one; as it happens @stefanpenner was discussing the possibility of doing this as well for something that's common and currently not super ergonomic with the public API. |
hey so I just tested this thinking it might address the issue of "natural key" which I submitted in #5237 but it didn't solve the problem... this is the assertion that is triggered when I try to create a record using a natural id which was previously used for a now destroyed record... it seems like this is related but I did a quick run through and I still get the assertion. any feedback appreciated |
@hjdivad any movement on this or thoughts around my previous comment? |
I was hoping to see this make it's way into 2.17, but admittedly that might have been a little ambitious. Can we set a goal of having this resolved in 2.18? |
Walked through this with @rwjblue and we've confirmed the regression that flag was meant to capture is indeed still tested and works. Additionally, the case that @runspired outlined also still works, but only because deletes won't trigger It remains the case that ManyArray.flushCanonical discards local changes for non-new records, but that's not the issue that the |
Failing test for the above issue: #5269 |
@hjdivad et al, thanks a lot for all your hard work on this. It really is appreciated. Hopefully I'm not pestering too much, but I'm curious what the next steps are toward resolving: #5136 . We had talked on slack and on workmanw/unload-relationships-bug#1 about how this was the critical step to resolving these issues. I believe the net out of that convo was once this issue was resolved, then it could be worked around by introduced adding custom adapter options on the application side. Example: // adapters/application.js
deleteRecord(store, type, snapshot) {
let options = snapshot.adapterOptions || {};
if (options.clientSideDelete) {
return resolve();
}
return this._super(store, type, snapshot);
} // controllers/comment.js
actions: {
unloadComment() {
let comment = this.get('comment')
if (comment) {
comment.destroyRecord({ adapterOptions: { clientSideDelete: true } }).
then(() => comment.unloadRecord());
}
}
} I'm curious what the general thoughts are on the state of this issue. Will application owners need to make these changes to restore functionality, or will there be further improvement to make this easier? Thanks again! |
Not to hijack but the issue above regarding loading/unloading is (I think) what is preventing us from moving past 2.12.x and is something we are really hoping gets resolved... our functionality works great on 2.12.x but there are other issues and obv we want to be on the latest |
@workmanw no, we're going to restore the client-side delete semantics of @rwjblue and I had some WIP on this Friday. |
Previously relationships were only cleared for new records. Now they
are cleared for destroyed records as well, allowing destroyed records to
be pushed back into the store and properly update their inverse
relationships.