I have an entity with 20 properties. I want those properties copied to one 
or more other entities and then save them with their original ID.
I started with something like this:

$price = clone $original;
$price->setId(23);
$price->someProperty = "foo";
$price->persist();
$price->flush();

But this creates a new record in the database instead of saving the 
properties to the already existing ID (23).

I'm now using a this approach:
$aOriginal = $original->getAsArray();
$price = Price::createFromArray($aOriginal);
$price->setId(23);
$price->merge();
$price->flush();

This approach seems to work, but the "getAsArray" method of this entity 
isn't part of Doctrine. So I created the array manually with 
$this->property. This is likely to go wrong someday, because the DB 
structure might change and it gives duplicate code.

Is there a better approach?

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to