I am trying to create Forum, which lists its Topics in a tree structure. I am using following Doctrine 2 (on mysql) entity to store Topic info.
/**
* @ORM\Entity
*/
class ForumTopic extends \Kdyby\Doctrine\Entities\BaseEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
public $id;
...
/**
* @ORM\ManyToOne(targetEntity="ForumTopic")
* @ORM\JoinColumn(name="ForumTopic", referencedColumnName="id", nullable=true)
* @var string
*/
public $parentTopic_id;
Every Topic has its own id and can be child of another one. If it is, it is stored in parentTopic_id. It works, but whenever I try to delete topic, this error appears.
#1451 - Cannot delete or update a parent row: a foreign key constraint fails (`sandbox`.`forum_comment`, CONSTRAINT `FK_65B81F1D8D182203` FOREIGN KEY (`ForumTopic`) REFERENCES `forum_topic` (`id`))
I tried to add onDelete="cascade" to row with "joinColumn", but it didn't help. How to fix it, so I can delete any topic?
EDIT:
Sorry for delay in responses, I had christmas to celebrate and stuff :-).
In this screen you can see data in the Table as requested.
**EDIT 2: ** Yes, it was a circular reference.