Nozbe / WatermelonDB

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

Unsure how to correctly set ids manually and skip id generation #1676

Open 1mike12 opened 1 year ago

1mike12 commented 1 year ago

So my use case is that I want the user to be able peruse entries in a big table while the app is connected to the internet. Then, the user has the choice of saving an entry for use offline. While offline, the user can also generate new entries that will be synced later. I think this is a fairly common usecase, think of browsing pinterest pins and saving them for offline viewing. Obviously we would not sync the entirety of pinterest using the standard syncing mechanisms.

Anyways, there were several suggestions on how to do this but the only working ones seem really weird and feel hacky https://github.com/Nozbe/WatermelonDB/issues/7#issuecomment-437368368

 ._raw.id=id

and by extension

record._raw = sanitizedRaw({ id: c.id, sid: c.id, username: c.username, .... }, contactCollection.schema)

Since it's so long ago, is this still the recommended way to do it? I can't see anything else mentioned about this usecase in the docs. Thanks 🙏

radex commented 6 months ago

Indeed the API tries really hard to discourage you from setting id manually, but ._raw.id=id is correct.