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

Primary keys should allow to be nullable #458

Closed
nirinchev opened this issue Apr 6, 2022 · 7 comments · Fixed by #851
Closed

Primary keys should allow to be nullable #458

nirinchev opened this issue Apr 6, 2022 · 7 comments · Fixed by #851
Assignees

Comments

@nirinchev
Copy link
Member

Right now we prevent primary keys from being nullable, but there's no reason for this. We should allow it.

@ianpward
Copy link
Contributor

ianpward commented Apr 6, 2022

Or should we ?

@nirinchev
Copy link
Member Author

We should 😄

@blagoev
Copy link
Contributor

blagoev commented Apr 7, 2022

I would like to understand more. Even though core supports it why would we allowing this. I would argue this in 110% of the cases is a mistake when defining the schema. What's the use case we are trying to cover?

@dotjon0
Copy link

dotjon0 commented Jun 23, 2022

The @PrimaryKey() is the UID for the DB document (https://www.mongodb.com/docs/realm/sdk/flutter/realm-database/define-realm-object-schema/#primarykey) so can not be null - how would we uniquely identify each DB document otherwise? It would be good as @blagoev mentioned to hear the full use case.

@nirinchev
Copy link
Member Author

null is a valid primary key/document id value in Realm/MongoDB. There can be exactly one object with primary key value equal to null the same way there can only be one object with a primary key value equal to 0 or "".

@dotjon0
Copy link

dotjon0 commented Jun 23, 2022

It would be good to understand the use case of having a null @PrimaryKey() DB document UID. Within our firm we always use unique ObjectID's for UIDs in order to keep our UIDs in a consistent format and data type - the same approach MongoDB Atlas functions as default if the _id UID is not provided when creating a document.

@nirinchev
Copy link
Member Author

If you're using ObjectId/UUID for your primary key type, then null is unlikely to be useful value. But Realm also supports int and string primary keys and there null is just another value that may have meaning to some - e.g. if you are storing user settings in a table, null could indicate the default settings and personalized settings can be stored with the user id as the primary key value.

Ultimately, this issue is about consistency across our products. All other SDKs and MongoDB/Atlas Device Sync support nullable primary keys and so should we. If that's not something you need, you are by no means forced to use it - it's completely optional.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants