I want to set primary key auto increment for my table.
Here is my Class. I have set primary key but I want it to be auto increment primary key.
publ
For react native
...
// this is the part where you are saving the newItem
realm.write(() => {
// handle the id
let id: any = realm.objects(this.Schema).max("id");
newItem.id = id === undefined ? 1 : id++;
realm.create(this.Schema, newItem);
resolve(newItem);
});
Well, @PrimaryKey is only indicates that field is a key. But you set it yourself when creating object and copying it to Realm. Consider using UUID.random(), ot increment it manually. (as in answer from comment): Realm Auto Increament field example