DDC-890: Association mapping 'One-To-Many, Self-referencing' with cascade and removes fk onDelete=restrict #5415

doctrinebot opened this Issue Nov 23, 2010 · 3 comments

2 participants


Jira issue originally created by user ardemiranda:

By using the association mapping 'One-To-Many, Self-referencing' removes the cascade.

How to follow the example below, and removed the first parent entity after the children entities.

And if you use foreign key onDelete=restrict the referential integrity error

A possible solution in the patch attached below

/*** @Table(name="category") **/
class Category
     * @Id
     * @Column(name="id")
    public $id;

     * @OneToMany(targetEntity="Category", mappedBy="parent", cascade={"remove"})
    public $children;

     * @ManyToOne(targetEntity="Category", inversedBy="children")
     * @JoinColumn(name="parent_id", referencedColumnName="id")
    public $parent;

    public function **construct() {
        $this->children = new \Doctrine\Common\Collections\ArrayCollection();
CREATE TABLE `category` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) unsigned DEFAULT NULL,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk*id_parent_id` (`parent*id`),
  CONSTRAINT `fk*id_parent_id` FOREIGN KEY (`parent*id`) REFERENCES `category` (`id`)

Comment created by @guilhermeblanco:

Seems to be fixed already in master.
Closing the ticket.


Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.3 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment