I have this function duplicateCourseAction whose goal is to ... duplicate a Course object
public function duplicateCourseAction(Request $request) {
if ($this
Trick here is that you must unset duplicate entity id. Otherwise breaks the logic of the doctrine. Doctrine has some known limitations. Also check this question, its very similar.
You can control what exactly gets cloned by overriding the __clone()
method in your Course
entity. You can set id
to null
and clone referenced objects if you need a deep copy.
The serialization/unserialization feels like a hack, so I recommend against using it.