Deep cloning an object : Clone vs Serialize

前端 未结 2 1239
既然无缘
既然无缘 2021-01-25 02:40

I have this function duplicateCourseAction whose goal is to ... duplicate a Course object

public function duplicateCourseAction(Request $request) {
    if ($this         


        
相关标签:
2条回答
  • 2021-01-25 03:00

    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.

    0 讨论(0)
  • 2021-01-25 03:04

    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.

    0 讨论(0)
提交回复
热议问题