On Dec 12, 3:05 pm, blake <[email protected]> wrote:
> Hello,
>
> I have a parent model with several children (mostly hasmany
> relationships, also 1 HABTM). Each child model could have several
> hundred rows, so I am looking for an efficient and clean way to
> duplicate all the child models. Ideally I want to end up being able to
> do Parent.duplicate() and have all associated children also
> duplicate themselves and associate with the new duplicated parent ID.
> Anyone know of a good clean way to do this?
Not specifically, however in principle:
read/find
unset all keys/foreignkeys
call create
call saveAll
You'll find however that saveAll only goes one relation deep, so if
depending on the depth of your data you may find you need to save
related data in a loop, or create a semi-recursive duplicate logic.
e.g.
function duplicate($data) {
$this->save($data);
$data = Set::merge($data, $this->read());
$this->OtherModel->duplicate($data);
$this->OtherModel2->duplicate($data);
$this->OtherModel3->duplicate($data);
.etc..
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---