Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Object(value:) doesn't create unmanaged objects recursively #5818
I'd like to initialize an object using
Obtain an unmanaged copy of the Object instance, with all of its child objects and relations being unmanaged (recursively).
It crashes when saving the newly created object. Why?
Steps to Reproduce
(I did this in Objective-C):
Populate the database with sample data, including adding objects to the
(I did this in Swift):
Version of Realm and Tooling
@christoff-1992 Luckily, in my use case, I actually didn't need the RLMArray of objects cloned, so I just cleared them (i.e.
Thanks, @rogerluan unfortunately for myself removing all the objects won't be an option. I am creating an unmanaged copy of the object as there is no undo functionality in Realm. The workaround will work but I have the joys of many nested objects
The main problem with changing it is that it's a breaking change: it's unlikely that anyone specifically wants to be accessing managed objects from their standalone copy of the parent, but if they aren't actually using those properties then changing to a deep copy would make what's currently a fairly cheap operation into something potentially very slow and memory hungry. It's not that rare to have a schema where every object is reachable from every other object, which means that
That said, we do clearly need a way to perform a deep copy out of a Realm. Early on we were wary about building something because it looked like it'd be a footgun that lead people in the wrong direction, but that hasn't really been a concern for years.
A potentially very simple solution would be a max depth parameter, which would also sorta let us punt on dealing with object cycles. Might have odd implications when the value isn't a Realm object, though? If you pass in a dictionary we have to fully recur and convert nested values to Realm objects.