I have an entity which has a relationship which contains settings (multiple). To add or delete an entity I have to use cascading, but it isn't working and I can't find the error in my code.
The entity:
/**
* @var DepartmentSettings
*
* @ORM\OneToMany(targetEntity="DepartmentSettings", mappedBy="department", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
*/
protected $departmentsettings;
The error I'm getting:
An exception occurred while executing 'DELETE FROM department WHERE id = ?' with params [13]:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`hotflo20`.`department_settings`, CONSTRAINT `FK_DCFBBAEFAE80F5DF` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`))
Hopefully someone can solve this issue. I'm really stuck at the moment
cascadesettings only appears then you operate with your entites via EntityManager. Then you make aDELETEquery it doent care. You need to setonDelete="CASCADE"inDepartmentSettingsentity which make a trigger in database.