phpsymfony1symfony-1.4

Copy object to other table - Symfony 1.4


I have two table:

First:
id | name  | password
 1 | peter | old

Second:
id | name  | password

I get object from table First:

$first = Doctrine::getTable('First')->find(1);

$copy = $first->copy();

$second = new Second($first);
$second->save();

or

$second = new Second($copy);
$second->save();

In both cases i have:

Second:
id | name  | password
 1 | NULL  | NULL 
 2 | NULL  | NULL

Is possible to make this copy?


Solution

  • Have you tried with toArray / fromArray ?

    $first = Doctrine::getTable('First')->find(1);
    
    $second = new Second();
    $second->fromArray($first->toArray());
    $second->save();