How should i connect a User with a Model?

I have a List Model (like a ToDo List).
I want to connect this List Model with a User so they can access (only) their own List’s.

I have now 3 options:

  1. Create a User Model with a userId field which includes the userID from auth. Then I could link this UserModel with the List. Inverse Relationship would allow me to get from a User to his List’s and the other way around.
  2. Use Custom User Data and link this with the List. (but I think this should be only used for metadata, see Documentation)
  3. Place in the List Model the userID which I get from auth. Than query always for this id from RealmAuth.

Option 1 is right now my preferred way to go, because option 2 seems not to be live (docs say CustomUserData is stale/updates slowly) and I want that the User can directly access the List’s he created.

I search for an efficient solution and I want to add later the feature that a User can share a List with other User.

[React Native, I am quite new to Realm]

Thank You for your Feedback in advance :slight_smile:

I would recommend going with Option 3. Add a userID to every List document, and then allow the user to just sync on lists they own.

If you want to use a different user identifier that’s not userID (like email), option 2 is also perfectly fine. As long as you stipulate that a user’s identifier / email doesn’t change, you could attach that identifier to every list object and user custom user data to associate a user document to the list that the user owns.

2 Likes

Thank you for your Answer! I will choose Option 2.