I have a document with an embedded document. When I create an object for the first time, everything works fine, but when I try to update a document, the embedded document is not updated.
class DocumentA { protected $docB; protected $valueA; } class DocumentB { protected $valueB; }
In my application, I request a document, update the values ββand save them to the data store.
// Variant A β Does not work $document = ... // find from data store $document->setValueA('Hello World'); $document->getDocB()->setValueB('foo baz'); $om->persist($document); $om->flush();
If I do not update the embedded document, but install a new one, everything works fine:
// Variant B - Does work $document = ... // find from data store $document->setValueB('Hello World 2'); $document->setDocB(new DocumentB()); $document->getDocB()->setValueB('foo baz 2'); $om->persist($document); $om->flush();
As I said, option B works fine. However, in my application, documents are more complicated, and it would be impractical for me to create a new object for an embedded document every time I have to update it. Is there a way to tell Doctrine ODM to look at the values ββof an embedded document to decide whether to update it?
source share