Hi, I’m used to using ORM and I find that Realm is very powerful and convenient, however, I find that updating RealmObject very cumbersome. It requires Write() wrapper and I have to make changes inside it, otherwise it will generate an error.
I understand that it requires transaction but I was hoping it follows more conventional method, i.e., just realm.CommitChanges() at the end without requiring realm.BeginWrite() to begin transaction.
In other words, any changes made to RealmObject are just temporary and it doesn’t begin transaction until CommitChanges is called.
I’m sure you know what I’m talking about but bere is scenario to illustrate the problem.
I have many UI options that are stored in Realm. Since it’s a RealmObject, whenever I change any one of them, I have to wraparound Write(). It is very cumbersome as the changes are made in many different places.
One other problem is that I cannot revert all the changes I made easily.
You also recommend making the transaction in one large group for better performance.
To make it easier, what I do is to create a temporary object and store all the changes myself.
When a user confirms the change, I copy the changes I made back to the RealmObject. It’s not very pretty and I think it should be done by Realm.
What I’m proposing is this.
- You can continue to use Write() wrapper. I think it’s still useful since it doesn’t need to copy to a temporary buffer to save memory.
- If you modify Realm object without Write(), you will store the changes to a temporary buffer instead of throwing an error. And later, if you call CommitChanges, it will start the transaction and store the changes.
I hope it makes sense.