The following message get thrown: "A cycle has been detected, so a topological sort is not possible. The getCycle() method provides the list of nodes that form the cycle." after removing/flushing an entity while using semantically correct doctrine syntax and sound logic
Current behavior
Blocking the flush process from removing the entity while using OneToOne relations.
More context here: Stackoverflow
Don't throw the error, there's no cycle (infinite loop?) here, just remove the entity.
I fixed the issue by adding the following attribute: #[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
Another solution could have been to manually clear the relations before removing the entity:
#[ORM\PreRemove]
public function onPreRemove(PreRemoveEventArgs $args): void {
/* Remove any references to self, as this will throw a CycleDetectedException */
foreach ($this->getPageTemplates() as $pageTemplate):
$pageTemplate->setNextPage(null);
$pageTemplate->setPreviousPage(null);
endforeach;
}
Bug Report
Summary
The following message get thrown: "A cycle has been detected, so a topological sort is not possible. The getCycle() method provides the list of nodes that form the cycle." after removing/flushing an entity while using semantically correct doctrine syntax and sound logic
Current behavior
Blocking the flush process from removing the entity while using
OneToOne
relations. More context here: StackoverflowHow to reproduce
OneToOne relations with
self
usingcascade:remove
Expected behavior
Don't throw the error, there's no cycle (infinite loop?) here, just remove the entity.
I fixed the issue by adding the following attribute:
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
Another solution could have been to manually clear the relations before removing the entity: