Deep copy operations?

Can you tell me whether there’s a way (best practice) to deep copy (meaning the bus obj and all it’s relationships)?

and being able to control which relationships get copied and which don’t would be a bonus :slight_smile:

Assuming that you mean a deep copy that is persisted vs just a deep copy in memory, you can read the object and all of its children using an include filter. The include filter will control which relationships are included as part of the copy.

Use the .toJSON() method on the retrieved item to get a native JSON object and recursively walk the tree removing id and parent foreign keys from the objects. This is done so that when you create the new ones the new ids will be assigned. Do not remove foreign keys that point at objects that are not part of the deep copy.

Finally pass the payload to the .createWithChildren behavior to create the top level object and all the items under it.