Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

[Question] How to extend children relation and fetch to retrieve also deleted records #324

Closed bogdancochioras closed 5 years ago

bogdancochioras commented 5 years ago

Hello, what is the best approach of overriding queries, fetch, relations to also include the deleted status (excluding the default not deleted condition)? I saw that the queryWithoutDeleted method is applied as the descriptor property in the Query constructor, would I need to override that descriptior? or is there a method to exclude the query from fetch or relation somehow simpler?

radex commented 5 years ago

@bogdancochioras Why do you want to retrieve deleted records? It's WatermelonDB's assumption that deleted records are inaccessible (only exist for sync purposes), and it's possible some things will break if you try to fetch deleted records.

here's the solution, but again, no promises it will work well in all circumstances: https://github.com/Nozbe/WatermelonDB/issues/5#issuecomment-428204005

bogdancochioras commented 5 years ago

@bogdancochioras Why do you want to retrieve deleted records? It's WatermelonDB's assumption that deleted records are inaccessible (only exist for sync purposes), and it's possible some things will break if you try to fetch deleted records.

here's the solution, but again, no promises it will work well in all circumstances: #5 (comment)

Thank you. The WatermelonDB Sync doesn't fit our use since we don't use WatermelonDB internal IDs on the back-end and need to sync almost realtime, on every action and we need to reconstruct the parent object that contains the deleted collection and other things from the parent so we would need also the related data to the deleted record in the sync so it was easier to handle deletion on our side.

radex commented 5 years ago

@bogdancochioras I see! Many people using 🍉 face this problem of not being able to use client IDs… If you manage to get a successfully working sync and all, perhaps you'd be willing to share what you've learned? I think it would be good to have a thread to try figuring out as a community the best approach for dealing with client and server side IDs — currently everyone is doing something else and has to implement a bunch of stuff from scratch… would be better to have a best practice and some support from 🍉

radex commented 5 years ago

I'll close this for now but feel free to reopen if there's still issues