after_relationship_delete logic hook deleting all records.

I have created following code to delete record from related module,when user click on a remove button.
I am facing a problem here that when i remove a single record it remove all the records from related module, instead of that single reocrd.
i am using “after_relationship_delete” logic hook.

        try {
            if (
                    isset($bean->rel_fields_before_value["cloud_lidmaatschap_con_contacten_1cloud_lidmaatschap_ida"]) &&
                    !empty($bean->rel_fields_before_value["cloud_lidmaatschap_con_contacten_1cloud_lidmaatschap_ida"])
            ) {
                $contactpersonen_id = $bean->rel_fields_before_value["cloud_lidmaatschap_con_contacten_1cloud_lidmaatschap_ida"];
                $contactpersonen = new cloud_Lidmaatschap();
                $contactpersonen = $contactpersonen->retrieve($contactpersonen_id);
                $contactpersonen->load_relationship('cloud_lidmaatschap_con_contacten_1');
                $contactpersonen->cloud_lidmaatschap_con_contacten_1->delete($bean->id);
            }
        }
        catch (Exception $ex) {
            $GLOBALS['log']->fatal($ex->getMessage());
        }

You seem to be deleting the relationship

$contactpersonen->cloud_lidmaatschap_con_contacten_1->delete($bean->id);

didn’t you want to delete an actual module record? And are you sure about using that $bean->id here?

Can you step through your code with a debugger? This should make it obvious what is happening. Check if you have a loop (when deleting relationships inside delete_relationship hooks, you risk having one).