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

find() returns deleted records #1830

Open
dcheli opened this issue Sep 3, 2024 · 3 comments
Open

find() returns deleted records #1830

dcheli opened this issue Sep 3, 2024 · 3 comments

Comments

@dcheli
Copy link

dcheli commented Sep 3, 2024

I recently discovered that if I execute a find() on a record collection using an id for a record that has been previously deleted with markAsDeleted(), the query will return the record.

for example:
const goal = await goalCollection.find(goalActivity.goal.id);

will return a previously deleted goal. I have 2 questions about this:

  1. Is this expected behavior?
  2. If it is expected behavior, what is the best course of action to determine if the record is deleted? I can look at the _raw._status field, but accessing the _raw property directly seems to be frowned upon.
    Thanks
@dcheli
Copy link
Author

dcheli commented Sep 5, 2024

Also, I'm using "@nozbe/watermelondb": "^0.27.1",

@KrisLau
Copy link
Contributor

KrisLau commented Sep 9, 2024

It is not expected behavior. Are you syncing your records or resolving syncs in some way?

If you only use Watermelon as a local database, destroy records permanently, if you synchronize, mark as deleted instead.

await somePost.markAsDeleted() // syncable
await somePost.destroyPermanently() // permanent

https://watermelondb.dev/docs/CRUD#delete-a-record

@dcheli
Copy link
Author

dcheli commented Sep 10, 2024

Thanks for the response and confirming that this is not expected behavior. I am not currently syncing my records, but that is the long term , well, in the next few months, hence I'm using markAsDeleted(). What seems to work rather then using the find(), is to just use:

.query(Q.where('my_field_id', someid))

If the record doesn't exist, it returns an empty array.

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

2 participants