How to link custom module information with several other modules

I have created a custom module and the information in this module might be populated as early in the sales process as Leads and then would be passed along to a converted opportunity and then if applicable, to a Quote. The information is related to all of these as a one-to-many relationship. All good…I see a sub-panel on all of the associated layouts. I don’t want to move or duplicate the data. I want to keep a common shared copy that can be referenced by all.

But I have trouble finding examples of how to link the same set of records between three modules (Lead, Opportunity, Quote). In this example, http://cheleguanaco.blogspot.com/2012/03/logic-hooks-lead-history-transfer.html, Angel is deleting the relationship from one module before adding it to another and there is no element of a custom module in this example. In this example, https://community.sugarcrm.com/sugarcrm/topics/logic_hook_to_add_relationship, there is a custom module, but it lacks the one-to-many relationship.

I guess I have two questions: 1) is it okay within Sugar/Suite to link back to the same records? Would this cause an issue? 2) if so, can anyone refer me to a good example that will do what I want?

Thanks for any help provided,
Dianna

Here is my code. I have marked the line that is experiencing the error. The error that I am getting is: PHP Fatal error: Call to a member function add() on a non-object in
/var/w
ww/html/suitecrm/custom/modules/Leads/CopyApplications.php on line 39

Any help will this would be greatly appreciated.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<?php class CopyApplications_class { function CopyApplications_method($bean, $events, $arguments) { $action = $_REQUEST['action']; if ($action == 'ConvertLead') //Must confirm it only triggers on conversion!! { $GLOBALS['log']->fatal('DURING CONVERT LEAD'); //Only perform this logic if an opportunity was created if (!empty($bean->opportunity_id)) { $GLOBALS['log']->fatal('OPP ID IS NOT EMPTY'); $opportunity_id = $bean->opportunity_id; $rel_name = 'leads_appkg_applications_1'; if ($bean->load_relationship($rel_name)) { //Access the associated Opportunity $opportunity = new Opportunity(); $opportunity->retrieve($opportunity_id); //Get all applications associated with lead $applications = array(); foreach ($bean->leads_appkg_applications_1->getBeans() as $applications) { $GLOBALS['log']->fatal('FOUND AN APPLICATION TO COPY'); $application_id = $applications->id; $rel_name = 'opportunity_appkg_applications_1'; $opportunity->load_relationship($rel_name); $GLOBALS['log']->fatal('COPIED APPLICATION'); $opportunity->opportunity_appkg_applications_1->add($application_id); <<<fatal('NO APPLICATIONS TO COPY'); } } } } ?>

I found my problem. I was using the wrong relationship name:

$rel_name = ‘opportunity_appkg_applications_1’; should be >> $rel_name = ‘opportunities_appkg_applications_1’;
$opportunity->load_relationship($rel_name);
$GLOBALS->fatal(‘COPIED APPLICATION’);
$opportunity->opportunity_appkg_applications_1->add($application_id); should be >> $opportunities->opportunity_appkg_applications_1->add($application_id);

But I still have a question about point several modules to the same information since it seems like things are either moved or copied from one module to another… is it okay within Sugar/Suite to link back to the same records? Would this cause an issue?