2

Is there some pros or cons to not implement that feature?

I know some solutions exist and that it's on there road maps but are there any advantages behind that decision that we are not award of?

Asme Just
  • 1,287
  • 5
  • 27
  • 42
  • I think there are just more important things to do, considering you can set up autoincrement primary key with 6 lines of code – EpicPandaForce Oct 27 '16 at 16:29
  • Yeah but, it's one of those things that usually comes out of the box, so I guess there must be something we're missing... Right? – Asme Just Oct 27 '16 at 16:41
  • 1
    What is the use case you're trying to solve? There are probably better alternatives than an auto-incrementing primary key. – Michael Oct 27 '16 at 23:34
  • @Michael ... use case? Any actually, just was wondering if there are something am missing with that design decision. Better alternatives...? Like what? – Asme Just Oct 28 '16 at 03:28
  • Like UUID? which doesn't depend on any IDs stored but it will be good enough to be unique for any common cases. – beeender Oct 28 '16 at 05:00
  • I didn't know heard about UUID til I tried to find a workaround about this "problem". And from what I've read, auto-increment seems to be safer since we're guaranteed to not have collision. So I'd rather call this a _solution/workaround_ than _better alternatives_ .Right? – Asme Just Oct 28 '16 at 05:40
  • It's really really easy to set up auto-increment primary keys though http://stackoverflow.com/a/40175572/2413303 – EpicPandaForce Oct 28 '16 at 07:02

1 Answers1

5

In a discussion on Github (see realm/realm-cocoa#2591) the Realm team said there are no plans for support any auto increment field, even if there's a few lines of code a developer can use for implementing this feature as you said.

From a Realm member in the discussion:

We decided that we're not going to support this feature, because we would be unable to support it with simultaneous access from multiple processes.

So that's it.

Orlando
  • 1,509
  • 2
  • 19
  • 27
  • That's kinda weird though. They do support multi-process locking during write transactions. – EpicPandaForce Oct 27 '16 at 19:34
  • 2
    A more important issue is that auto-incremented keys do not work with offline sync across devices. Also Realm do not need keys for relationships, which is the primary reason they exist in SQL. The two other use cases are `sort after created` and `key for lookup`. If you want to sort based on when the object was created, having a `Date created = new Date()` will work. If it is to have a unique key for easy lookup `String id = UUID.random().toString();` will work. – Christian Melchior Oct 28 '16 at 07:32
  • Thank you, I think it'd be great if they let new comer (like me from the SQL world) know about this from the docs. – Asme Just Oct 30 '16 at 01:39