1

I m thinking about a workaround for realms inability to check for duplicate compound keys on entities (no compound keys supported):

what about declaring a compound key class - and then declaring a primary key of that compound key class as field of the entity class ?

Can that be used to workaround the lack of compound key support ? Has anybody tried that ?

  • 1
    While compound keys are not specifically used, it's pretty simple to implement them. See this [Compound Keys](https://github.com/realm/realm-cocoa/issues/1192). The idea is to combine two keys into a third (stored) key and use that. – Jay Sep 18 '16 at 13:43
  • Thank you - I however have compound keys defined on the backend. I use the same entity classes for deserializing JSON coming from the backend, and it would be very handy to not have to modify them at all when storing them with realm. With a compound key solution youre suggesting (basically making a combination), I would have to change the entity classes. And then whenever they change on the backend, I d have to change them on my android app as well, manually. – Johnny Realmony Sep 18 '16 at 15:02
  • You can parse the JSON on your own, or maybe just manipulate the JSON object to insert the compound key with its field name then calling Realm API to save. – beeender Sep 20 '16 at 04:11

0 Answers0