Can I clone an object and its children if a need a new copy with a different ID?


#1

I have an object of type Contact that has:

  • a primaryKey id of type “string”
  • a bunch of properties of different types
  • and a property that is a list of other objects (notes)

I need to make a copy of a specific Contact (ID known) that must have the exact same values for all properties, including the list of notes (they need to be cloned as well) but different ID.

Is there any feature in Realm that does this?
Or do I need to iterate all props and child notes and manually create my Contact copy?

Thanks!


#2

When you get a realm object from a realm, you will receive a managed object - this object means that the object knows the realm it comes from.

You can create an unmanaged copy of an object, but unfortunately thats not recursive - meaning if you have a list of object on the Contact then they will stay managed, and cant be re-inserted.

See this issues: