Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone/copy a sql record with CakePhp?

How to clone/copy a sql record with CakePhp? Is there a native way or do I need to find my record and then save it?

like image 536
Dacobah Avatar asked Jan 09 '13 14:01

Dacobah


2 Answers

You need to use the find and save function.

$record = $this->Model->findById(1);
$record['Model']['id'] = NULL;
$this->Model->save($record);
like image 106
noslone Avatar answered Oct 28 '22 18:10

noslone


There is no native "copy" command by itself. But a find/read operation followed by a create/save should work.

$row = $this->Model->findById(1);
$this->Model->create(); // Create a new record
$this->Model->save($row); // And save it

Would copy the row with id 1.

like image 26
Oldskool Avatar answered Oct 28 '22 18:10

Oldskool