Rubius / Realmius

Realtime sync engine for Realm mobile database (Xamarin) with DotNet backend
Apache License 2.0
18 stars 8 forks source link

Get rid of the need to add attribute to reference properties #9

Open Shaddix opened 7 years ago

Shaddix commented 7 years ago

Now to sync references you have to do the following: 1) Server-side: have a scalar property with reference's key to pass to the client. E.g.:

        [ForeignKey(nameof(ReplyId))]
        [JsonIgnore]
        public virtual Message Reply { get; set; }
        public string ReplyId { get; set; }

That way ReplyId property is synced between the server and the client.

2) Client-side:

        [JsonProperty("ReplyId")]
        [JsonConverter(typeof(RealmReferencesSerializer))]
        public Message Reply { get; set; }

3) For many-to-many we don't need [JsonProperty] on the client, but we need JsonConverter on the server:

        [JsonConverter(typeof(RealmServerCollectionConverter))]
        public virtual IList<ItemCategory> Categories { get; set; }

Since we control json serialization on both ends, there should not be a need for the user to put in additional attributes

jromerus commented 6 years ago

Does it means that I need to use Json attributes in a RealmObject to properly get referenced properties work?