Affects Version/s: 1.2.2
Fix Version/s: None
Retreive an object "A" and some related object from the database.
Export it into an array.
Create an other instance of "A" and import array from the previous exported array.
Just save the new instance.
Doctrine re-create the object into DB. If you have some integrity constraint like primary key, you will see an SQL error.
In the following example with "video" and "tags", Doctrine want to re-create the video and tag objects.
The reason is that the exported array doesn't include the "_identifier" key.
In my mind, the problem show and other problem, that we are force to use the "identifier" or assignIdentifier on the Model domain object to work with an existing object.
Doctrine know the Primary key of all the model domain objects. Why Doctrine doesn't use the assignIdentifier when the user change the PK of the Model domain object... In this case, assignIdentifier could be into a private scope.
$oVideo = Doctrine_Query::create ()
->select ("video., tags.")
->from ("Model_Video video")
->leftJoin ("video.tags tags")
->where ("video.id_show = 500")
$oVideoArray = $oVideo->toArray();
$oVideoBis = new Model_Video ();
$oVideoArrayBis = $oVideo->toArray();