CakePHP 2: Error deleting record with HasOne relationship


Hi all

I am trying to delete a record in CakePHP (2.9.5) and I am getting the following error when trying to delete a record - unable to delete a related record (member) that has a related table with as HasOne relationship. No problem with other HasMany related records.

Error: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (aal_online_admin_test.member_stats, CONSTRAINT fk_member_stats_members FOREIGN KEY (member_id) REFERENCES members (id))

I have a constraint on the member_stats table

CONSTRAINTfk_member_stats_membersFOREIGN KEY (member_id) REFERENCESmembers(id)

The member model has the following

public $hasOne = array(
	'MemberStat' => array('dependent' => true)

and the memberStatus model has

public $belongsTo = array('Member');

Everything was fine in the world until I added this related record - deleting a member deleted all records with HasMany relationships.

We have similar constraints on other tables e.g.

CONSTRAINTfk_member_units_membersFOREIGN KEY (member_id) REFERENCESmembers(id)

'MemberUnit' => array('dependent' => true)

The easy thing is to remove the constraint, but I want to understand if its a cakePHP bug or something stupid I’ve done.