What did you set the ON DELETE
clause in your foreign key constraint to? For most RDBMS if you don't specify one, it sets it to ON DELETE NO ACTION
which means you can't delete one row if another references it.
If it makes sense, you should update that ON DELETE
to ON DELETE CASCADE
. If it doesn't and you only want to allow deleting sometimes, you can pass TRUE
to ->delete()
and it will force both to be deleted.
// Delete the record even if there are records that
// reference it with an ON DELETE NO ACTION constraint
$record->delete(TRUE);