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 FooEntity
has a meaning FooMapper
. Saving nested objects is performed by nested Mapper
s. Each Mappers
preserves its essence with Zend\Db\Sql\Insert
or, Zend\Db\Sql\Update
and calls the correct one Mapper
for sub-arguments, such as BarMapper
for BarEntity
.
Now, before I start with convenient Doctrine functions, such as cascade={"persist"}
, I want to save the hierarchy Mapper
and 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 , ? ?