I have a model which gives me an error when if i try to delete the entry from the database (due to constraint violation) .
The error message is:
An exception occurred while executing 'DELETE FROM pits_docmanager_domain_model_role WHERE id = ?' with params [2]: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`flow_db_pits_doc_manager`.`pits_docmanager_domain_model_role_role_accesspoints_join`, CONSTRAINT `FK_54B164455C544054` FOREIGN KEY (`docmanager_role`) REFERENCES `pits_docmanager_domain_model`)
#23000: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`flow_db_pits_doc_manager`.`pits_docmanager_domain_model_role_role_accesspoints_join`, CONSTRAINT `FK_54B164455C544054` FOREIGN KEY (`docmanager_role`) REFERENCES
pits_docmanager_domain_model\
)
And in my entities i have (role.php)
/**
* @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\AccessPoint> $role_accessPoints
* @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\AccessPoint",cascade={"remove"})
* @ORM\JoinTable(name="role_accesspoints",
* joinColumns={@ORM\JoinColumn(name="access_point_id",referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id",referencedColumnName="id")})
*/
protected $role_accessPoints;
and on the other file (accesspoints.php)
/**
* @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\Role> $accessPoint_roles
* @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\Role",cascade={"all"})
*/
protected $accessPoint_roles;
even tho i have the cascade option set in the property am still not able to remove that entry.
Edit: What i am trying to achieve is that..
Consider i have 2 models (roles and accesspoints). if i delete a role, i need to be able to delete that role and the corresponding data related to that in the join table (and want to keep the data in accesspoints untouched)
Edit 2: Fixed (removed all the options from the cascade param and it worked)
/**
* @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\AccessPoint> $role_accessPoints
* @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\AccessPoint",cascade={})
* @ORM\JoinTable(name="role_accesspoints",
* joinColumns={@ORM\JoinColumn(name="access_point_id",referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id",referencedColumnName="id")})
*/
protected $role_accessPoints;