public function persistEntity(bool $flush = FALSE) { $containers = iterator_to_array($this->getComponents(TRUE, self::class)); array_walk($containers, function (self $container) { $container->initEntityRelations(); }); $this->setValues($this->getValues()); $this->repository->persist($this->entity); if ($flush) { $this->repository->flush(); } }