How to create a logic hook to create Relationship

Hi

I am trying to create a logic hook to insert record in relationship table.

I have created relation between Opportunity and a custom module Opportunity Items.

this is my code:

                       $oppItemsId = '' ;

                       $OpportunityId='';
                        $rel_name = 'opportunities_s_opportunity_items_1';

                        $oItems = new Opportunity();
                      
                        $oItems = retrieve($OpportunityId);                       
                        $oItems->load_relationship($rel_name);
                        $oItems->$rel_name->add($oppItemsId);  
                        $oItems->save();

it will give error "Call undefined function  retrieve() " .

can any one please help me.

Thank you in advance.