1

I'm trying to get a handle on how to use custom Swift classes to model my Syncano backend. I have classes MPUser and MPUserProfile exactly as described in this guide. However, instead of adding an avatar field, I'd like to add a friends list. Should this property be:

  • An array of MPUsers
  • An array of MPUserProfiles
  • An array of integers corresponding to the other users' IDs
  • Something else?

Edit: their page on classes makes it sounds like I would want an array of type Reference (referring to users' IDs) but their arrays can only have string/int/boolean/float. I'm now wondering if an array of (non-Reference) integers will work fine.

Thank you for your help.

Connor Neville
  • 7,291
  • 4
  • 28
  • 44

2 Answers2

0

An array of MPUser's definitely. I haven't used Syncano so I may be utterly wrong on this, but having using Couch, Firebase and played with Realm...

The whole idea of key/value/object/document stores like these is that details of the storage are abstracted away in the back end. So you put an MPUser in an array, and when you access that array sometime later you get it back. Totally magic. That the DB itself might physically store that as an Int64 or inline the entire string is of no interest to you - data in, data out.

I suspect you have worked in the SQL world, which is why you put that last option there? Generally that's not how you work in object stores - thank gawd.

Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98
0

Currently Syncano doesn't support holding arrays of references. It's something we are working on (adding many-to-many relationships), but in the meantime you should could safely just use array type and store ID of referenced objects in there.

When you store array of IDs, you can use either ID of a user, or ID of a user profile.

The connection between them is as follows: User is a physical user that logs into your app. His profile is an object that belongs to him. User A cannot be accessed by user B, but profile of user A can be accessed by user B.

You can get a profile of user A either by using profile ID (object id from user_profile class), or by using user A id (owner field in object inside user_profile class).

Depending on which route you take, you can then ask Syncano for list of all friends doing either:

  • give me all user profiles, where ID is in [array of user profile IDs]
  • or, give me all user profile, where owner is in [array of user IDs]

User Id and his profile