[DDC-1504] Cascade remove in OneToMany relation doesn't work Created: 22/Nov/11  Updated: 14/Mar/12  Resolved: 14/Mar/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.2
Fix Version/s: 2.2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Gaetan Rousseau Assignee: Benjamin Eberlei
Resolution: Incomplete Votes: 1
Labels: None

Ubuntu 10.10, syfmony 2.0.4

Attachments: File DDC1504GitlessTest.php    


I have two entities :

class Structure
    // Id and other variables

     * @var ArrayCollection $employees liste des employés d'une structure
     * @ORM\OneToMany(targetEntity="Uriae\EmployeeBundle\Entity\Employee", mappedBy="structure", cascade={"all"})
    private $employees;

class Employee
    // Id and other variables

     * @var integer $structure
     * @ORM\ManyToOne(targetEntity="Uriae\StructureBundle\Entity\Structure",inversedBy="employees")
    private $structure;

The problem is when I used tests and I wan't remove a Structure the Employees aren't removed.

// Doesn't work

// Bad solution but it works
foreach ($employee as $employees)

Comment by petrs [ 30/Nov/11 ]

The same problem, described here

Comment by Gaetan Rousseau [ 30/Nov/11 ]

I know, it's me who answered. But the solution i've found is "ugly".

Comment by Benjamin Eberlei [ 15/Dec/11 ]

Fixed formatting

Comment by Nurlan Turdaliev [ 27/Dec/11 ]

If you add orphanRemoval="true" it works.
But I think doctrine should somehow let the user know about this problem (throw exception, etc.)
Maybe it worths making orphanRemoval=true when cascading=remove?

Comment by Benjamin Eberlei [ 28/Dec/11 ]

1. orphanRemoval is not the right solution, it has different semantics. If you want this semantics the solution is ok.
2. Has anyone tried updating to anything above 2.1.2?
3. I cannot reproduce with a test-case against the current master or 2.1.5

I need a better testcase. Attached is the one i am working with.

Comment by Benjamin Eberlei [ 14/Mar/12 ]

No feedback given.

Generated at Thu Oct 08 19:52:26 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.