I am transferring DBAL ZF3 applications to Doctrine and want to go step by step. I am currently using a hierarchy of objects Mapper. Each object in the hierarchy FooEntityhas a meaning FooMapper. Saving nested objects is performed by nested Mappers. Each Mapperspreserves its essence with Zend\Db\Sql\Insertor, Zend\Db\Sql\Updateand calls the correct one Mapperfor sub-arguments, such as BarMapperfor BarEntity.
Now, before I start with convenient Doctrine functions, such as cascade={"persist"}, I want to save the hierarchy Mapperand just save the top level of the nested object with persist(...)and flush().
But when I try to do it
public function save(AbstractDataObject $dataObject)
{
$newLogicalConnection = $this->logicalConnectionMapper->save($dataObject->getLogicalConnection());
$newUser = $this->userMapper->save($dataObject->getUser());
$dataObject->setLogicalConnection($this->entityManager->find(LogicalConnection::class, $newLogicalConnection->getId()));
$dataObject->setUser($this->entityManager->find(User::class, $newUser->getId()));
$this->entityManager->persist($dataObject);
$this->entityManager->flush();
return $dataObject;
}
I get an error
A new entity was found through the relationship 'MyNamespace\DataObject\AbstractEndpoint#externalServer' that was not configured to cascade persist operations for entity: MyNamespace\DataObject\ExternalServer@000000006098ccff0000000068c23676. To solve this issue: Either explicitly call EntityManager
, Doctrine, , -, . ? cascade , Doctrine .
Doctrine , ? ?