I have an entity, "AnnualReport", which accepts a collection of entities, "AnnualReportStaffing". An annual report has four different Staffing sections and hence four of these collections (ArrayCollection). Since I can't use a traditional one-to-many relationship, I have to use One-To-Many with Join Table as described here.
So, for example, one of my Staffing collections is defined as such in my AnnualReport class:
/**
* @ORM\ManyToMany(targetEntity="AnnualReportStaffing", cascade={"persist"}, orphanRemoval=true, fetch="LAZY")
* @ORM\JoinTable(name="annualreports_staffingtenure",
* joinColumns={@ORM\JoinColumn(name="staffing_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="annualreport_id", referencedColumnName="id")},
* )
*/
private $staffing;
Now when it comes time to delete an AnnualReport, Doctrine removes the relationship between the report and the Staffing inside the join table, but it does NOT remove the associated AnnualReportStaffing entities. I tried adding cascade={"remove"}, but I get a foreign key violation because it is trying to remove the Staffing entity before the join table association is deleted.
What is the best way to remove the orphaned Staffing entities? Obviously orphanRemoval=true is not the answer.