public function doPersist()
{
if (!$this->isModified) {
return;
}
$toRemove = [];
foreach ($this->toRemove as $entity) {
$id = $entity->getValue('id');
$toRemove[$id] = $id;
}
$toAdd = [];
foreach ($this->toAdd as $entity) {
$id = $entity->getValue('id');
$toAdd[$id] = $id;
}
$this->added += $this->toAdd;
$this->removed += $this->toRemove;
$this->toAdd = [];
$this->toRemove = [];
$this->isModified = false;
$this->collection = null;
if ($this->metadata->relationship->isMain) {
$this->getRelationshipMapper()->remove($this->parent, $toRemove);
$this->getRelationshipMapper()->add($this->parent, $toAdd);
}
}