Nozbe / WatermelonDB

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

Error looking at a record that has been deleted #1331

Open brunochimenes opened 2 years ago

brunochimenes commented 2 years ago

I have a product and brand table and on my mobile app, I'm using watermelondb with mysql. On my API, I'm using paranoid, so, I ain't deleting my records from database, but adding a value to deleted_at. So, when I delete a brand on my site , I send an API call and set the deleted_at to that specific brand. But on mobile, the brand record is deleted, but the brand_id still has the value that references the brand that got deleted. How can I handle an observe( ) on my app, since it breaks the application when it tries do find the brand_id that doesn't exists anymore?

Captura de tela 2022-05-20 165642

I'm using this version:

"@nozbe/watermelondb": "^0.23.0",
"@nozbe/with-observables": "^1.4.0",
"react-native": "0.64.1",
1mike12 commented 2 years ago

are you not "cascading" the deletion on your backend to the product table by setting deleted_at on all products associated with that brand?

brunochimenes commented 2 years ago

No, here we are not cascading the records associated with the brand. Do you have any idea how to cascade in watermelondb, where I can, after syncing, check if the brand has been deleted and after that, removes the connection between brand on product, setting the brand id as null ?

KrisLau commented 2 years ago

@brunochimenes You can do this: https://nozbe.github.io/WatermelonDB/Writers.html?highlight=delete#delete-action

3210jr commented 1 month ago

@brunochimenes You can do this: https://nozbe.github.io/WatermelonDB/Writers.html?highlight=delete#delete-action

new link for future wanderers: https://watermelondb.dev/docs/Writers#delete-action