I’m trying to duplicate an object (document) with its related items (document groups and tvs values), but don’t know the better way to do this.
to copy the document :
<?php
$object= $xpdo->getObject('sitecontent',$model);
$object->_new=true;
$pkname=$object->getPK();
$object->_fields[$pkname]='';
$object->save();
?>
get all related items of $model with getOne and getMany and foreach:
- empty their PK
- set their _new fields to true
- set their foreign key accordingly to the new PK of the document created
- save them
Is the above method a good one ?
I having difficulty to understand how related items really works, when they have loaded in the object and how avoid recursive call when parsing them.
Thanks for your works and your time.