Closed s0nerik closed 7 years ago
Hi @s0nerik, thanks you very much for your contribution. Create and save methods closes the realm instance used to persist the entities into database. For that reason, the managed objects returned by these methods are no longer valid. I'm not very happy with the idea of returning invalid managed objects. If you try to modify any property, you will get an exception. What do you think about it?
Hi @vicpinm, my code works well in situations where there's at least one Realm instance is opened in the same thread before saving the objects. I do agree that it would be inconvenient to replace the existing methods with the ones that return managed objects. IMO, it would be much more convenient to create a separate set of methods that would return managed objects (with a doc that these should only be used in the situations where there already exists an opened Realm instance in current thread) and call them something like createManaged
, saveManaged
and so on. What do you think? If you don't have objections - I can push the commit adding such methods.
I agree with you. Second aproach (with createManaged and saveManaged) seems to be more convenient. I guess you will need to pass your realm instance to these methods. You are welcome to make a pull request.
Thanks you very much.
Hi @vicpinm, I've updated my fork with the changes we've talked about. I think this should be pretty safe to merge now.
Thanks you very much. I will upload a new version to maven in a few days.
Having the managed object being returned by these methods seems more convenient than having to query a managed object right after it's creation.