Is there a way to duplicate an ORM object with all it's relations and save it as a new record?
For example I have structure like this:
1. Building has many Sectors
2. Sector has many Datapoints belongs to Building
3. Datapoint belongs to Sector
I would like to duplicate loaded Building model with all relations and save it as a new record. Thanks for the tips.
There is no simple solution, as you'll have to copy all objects in the entire chain, which means recursing through all defined relations.
You can clone() existing objects, but all relations (except many-to-many) will be reset.