Let's say I have entity $e
. Is there any generic way to store it as another row, which would have the same entity data but another primary key?
Why I need this: I'm implementing some sort of Temporal Database schema and instead of updating the row I just need to create another one.
Try cloning and add the following method to your entity
You may need to detach the entity before persisting it. I don't have my dev machine handy to test this right now.
Update
Just tried using a simple SQLite demo. You shouldn't need to do anything. The following worked for me without adding a
__clone()
method or doing anything else out of the ordinaryOnce flushed, the
$new
entity had a new ID and was saved as a new row in the DB.I would still null the ID property via the
__clone()
method as it makes sense from a pure model view.Update 2
Digging into the Doctrine code, this is because the generated proxy classes implement
__clone()
with this important line