-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy Entity with all its collections #15
Comments
Could you try debugging your code (with xdebug)? |
Sadly I could not get xdebug to work in my centos server... I have not used it before, and I will have to setup a virtual machine for this specific task.. So, I'll need some time.. I've created a simplified version of the model using sqlite instead of mysql and everything worked as expected.. I guess the problem must be in my domain classes. They are quite complex, as Paginas have a Parent-Child relation and there are other relationships as each "Pagina" haves a "Contents" collection as well.. I don't see why it does't work, but I will keep loking into it.. A quick question, the foreach ($reflectedObject->getProperties() as $property) {
echo $property->getName() . "\n"; //DEBUG
$this->copyObjectProperty($newObject, $property);
} I get this output:
And none of these properties are from my class, but from the Proxy |
It seems that I have found the problem... In my code I am getting a different object first from the database, which is related to the object I want to clone.. this class ( If I query the Sitio first, doctrine returns a pure This code works as excpected. $p = $this->entityManager->find('Domain\Plantillas', $id_plant);
$sid = (int)$p->getSitioDemo()->getIdSitio();
$this->entityManager->getUnitOfWork()->clear();
$s = $this->entityManager->find('Domain\Sitios', $sid); So, the problem is, if the entity is cached by the doctrine's UnitOfWork DeepCopy wont work.. and only will copy the "root" object and not it's "child" references.. Should I close this issue? |
So to sum up (if I understood correctly), cloning a proxy object doesn't work? Maybe we could either make it work, or make it fail more explicitly? (e.g. throw an exception if the object is a proxy?) |
Exactly.. but it should be analyzed better, because the proxy of Let me test this further |
I am merging this issue with #18 (same topic) so closing this one. |
I have a parent entity named "Sitios" that haves 3 OneToMany associations: "Archivos", "Paginas" and "Hostings"... I am trying to clone the site including the files and pages, and resetting hostings to an empty collection and a "desarrollador" property that needs to be set to null.
this is my code:
But only the Sitio class gets cloned and all the references remains to the original Paginas and Files objects... the desarrollador attribute is not set to null and hostings is alredy empty, so I cant tell if it is working or not...
I have also tried with the collections example
but had no luck... can anyone give me a hand please?
The text was updated successfully, but these errors were encountered: