How to save object data collection in doctrine2 custom type?

In essence, it is an object collection with a custom type. The problem is that when you update, does not work convertToDatabaseValue. As I understand it, the doctrine does not understand that an object collection is changed.

class Record
{
...
/**
 * @ORM\Column(type="ContentContext_RecordTranslationcollection")
 * @var RecordTranslationCollection
*/
 private $translations;

...
 public function __construct ( )
{
 $this->translations = new RecordTranslationCollection();
}
....
/**
 * @param RecordTranslation $translation
*/
 public function addTranslation(RecordTranslation $translation): void
{
 /** @var RecordTranslation $translation */
 foreach ($this->translations as $currentTranslation) {
 if ($currentTranslation->getLocale() === $translation->getLocale()) {
$this->translations->removeElement($currentTranslation);
break;
}
}
$this->translations->add($translation);
}
 }


public function convertToDatabaseValue($collection, AbstractPlatform $platform)
{
 // if update, here not fall
}


 public function convertToPHPValue($json, AbstractPlatform $platform)
{
 $data = json_decode($json, true) ?? [];
 $collection = new RecordTranslationCollection();
 foreach ($data as $translate) {
 $collection->add($this->hydrator->hydrate($translate, RecordTranslation::class));
}
 return $collection;
 }


If somehow subverted the clone, then everything works. Any idea how to solve?
June 8th 19 at 16:45
0 answer

Find more questions by tags Doctrine ORM