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    


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 by Guilherme Blanco [ 23/May/12 ]

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

Generated at Wed Nov 25 11:31:43 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.