I tried cascade remove on the 'file' entity that keeps my 'expanse' entity from removing. But this doesn't work.
The error:
Cannot delete or update a parent row: a foreign key constraint fails (zioo
.files
, CONSTRAINT FK_6354059F395DB7B
FOREIGN KEY (expense_id
) REFERENCES expenses
(id
))
The file entity code:
/**
* @ORM\ManyToOne(targetEntity="Expense", inversedBy="files", cascade={"remove"})
* @ORM\JoinColumn(name="expense_id", referencedColumnName="id")
*/
private $expense;
The expanse entity code:
/**
* @ORM\OneToOne(targetEntity="File", cascade={"persist"})
* @ORM\JoinColumn(name="file_id", referencedColumnName="id")
*/
private $file = null;
/**
* @ORM\OneToMany(targetEntity="File", mappedBy="expense", cascade={"remove"})
*/
protected $files;
If a expanse gets deleted the file associated with it should be deleted too.