Reputation: 1376
To make it quick, I use Doctrine2 on entities.
One of my entities, User, possess a Contact through a 1 to 1 relationship.
I create both of them at the same time, persist the "children of the user" (here, his contact) and then proceed to persist the user itself. I do that very generically :
$em = $this->getDoctrine()
->getEntityManager();
$em->persist($object->getChildren()); //object->getChildren() is the Contact here
$em->persist($object); // $object is my User
$em->flush();
The persistence of the contact worked once (I don't really know how or why) but since then everytime I persist the User that way, it fails, giving me this error message :
A new entity was found through the relationship 'Aurae\UserBundle\Entity\User#contact' that was not configured to cascade persist operations for entity: Aurae\UserBundle\Entity\Contact@00000000554b2adc000000007fa05d30. Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Aurae\UserBundle\Entity\Contact#__toString()' to get a clue.
I tried declaring cascade persist in the User, but it didn't change anything.
What's the correct way to persist the Contact with the User?
Upvotes: 0
Views: 789
Reputation: 1376
cascade={"persist"}
on the Contact declaration in User solved the problem. Case closed.
Upvotes: 1