Look into deferring foreign key checks until flush finished (DDC-954)

[DDC-890] Association mapping 'One-To-Many, Self-referencing' with cascade and removes fk onDelete=restrict Created: 23/Nov/10  Updated: 23/May/12  Resolved: 23/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: 2.3
Security Level: All

Type: Sub-task Priority: Major
Reporter: André Ribeiro de Miranda Assignee: Guilherme Blanco
Resolution: Fixed Votes: 1
Labels: None

Attachments: Text File patch.diff    

 Description   

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

Category.php
<?php
/** @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`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC


 Comments   
Comment by Guilherme Blanco [ 23/May/12 ]

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

Generated at Thu Apr 17 09:49:46 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.