Constrainst error Cakephp 3.2


I am new to cakephp and loved it as it does an amazing job at building the application within minutes. But I am having trouble with some of the data records.

I have two tables employees and locations with an association location hasmany employees / employees belongsto locations

when I delete a location which is associated with an employee, I get the mysql error “Integrity constraint violation” I tried using beforeDelete() to find the employee who has the location_id but it does not do what it needs to do.

Help me with the code

Thanks in advance!