I use symfony cmf seoBundle. My entity class use SeoAwareTrait. When I try to update my seo properties(i use code below) I get result with old values of properties.
$entity = $this->galleryManager->findByLink($link);
$entity->getSeoMetadata()->setTitle($metaTitle);
$entity->getSeoMetadata()->setMetaDescription($metaDescription);
$entity->getSeoMetadata()->setMetaKeywords($metaKeywords);
$em->persist($entity);
$em->flush();
When I try to clone my seo properties Doctrine successfully save my new values:
$entity = $this->galleryManager->findByLink($link);
$entity->getSeoMetadata()->setTitle($metaTitle);
$entity->getSeoMetadata()->setMetaDescription($metaDescription);
$entity->getSeoMetadata()->setMetaKeywords($metaKeywords);
$entity->setSeoMetadata(clone $entity->getSeoMetadata());
$em->persist($entity);
$em->flush();
Why in the second case the doctrine updates the result, but not in the first? Do I correctly understand that the doctrine does not perceive changes in the properties that refer to other objects?
In the first example you call the methods "setTitle", "setMetaDescription", "setMetaKeywords" on the result of "getSeoMetadata". This result is not $entity, but you excplicity flush only $entity.
See:
Returns something (i gues a object) and you set the data on the object not on $entity:
In the above sample "setMetaKeywords()" is called on the RESULT of "getSeoMetadata()". What you get back from this method?
I would do it this way: