How to find relationships to emails module?

Hi,

I have a method where I am finding if there is a relationship between the emails modules and the notes module.  Normally I would go to studio to view all the relationships on a module, but it is not listed for emails.  I understand that emails is a special module used for workflows and other modules and that is why it isn't visible in studio.  Is there any way at all to see it relationships?

Here is my code thus far.

/**

*

* Creates a note in relationship to a case that already exists

* where the information in the note is that of the email.

* The purpose of doing this is so that the emails will show up

* in the sugarCRM portal.  The portal does not have the ability

* to view emails thus this work around.

*

* @param $email

* @param $case

*/

public function handleCreateNoteOnCaseFromEmail($email, $case){

   try{

       //create new note, it will have an id automatically when saved

       $newNote = BeanFactory::getBean("Notes");

 

       //get the attachment information from notes created from this email

       if($email->load_relationship("Notes")){

    THIS IS WHERE I NEED THE RELATIONSHIP

       }




       //get data from the email and put it into note

       $newNote->date_entered = $email->date_entered;

       $newNote->date_modified = $email->date_modified;

       $newNote->modified_user_id = $email->modified_user_id;

       $newNote->assigned_user_id = $email->assigned_user_id;

       $newNote->created_by = $email->created_by;

       $newNote->created_by_name = $email->assigned_user_name;

 

       //This displays as the subject in the sugarCRM portal

       $newNote->name = $email->name;

 

       $newNote->contact_name = $email->contact_name;

       $newNote->contact_id = $email->contact_id;

       //important for this show in portal

       //1 means show, 0 means don't show

       $newNote->portal_flag = "1";

       $newNote->team_id = $email -> team_id;

       $newNote->contact_email = $email->from_addr;

 

       //description is shown in portal

       $newNote->description =

           "\n" .

           " From: " . $email->from_addr . " \n " .

           " From Name: ". $email->from_addr_name . "\n" .

           " To: " . $email->to_addrs_emails . "\n" .

           " To Name: " . $email->to_addrs_names . "\n" .

           " Cc: " . $email->cc_addrs_emails . "\n" .

           " Cc Name: " . $email->cc_addrs_names . "\n" .

           " Bcc: " . $email->bcc_addrs_emails . "\n" .

           " Bcc Name: " . $email->bcc_addrs_names . "\n" .

           $email ->description;

 

       //associate the case with this note

       $newNote->parent_type = "Cases";

       $newNote->parent_id = $case->id;

       $newNote->parent_name = $case->name;

 

       //save note to db

       $newNote -> save();

 

   }catch(Exception $e){

       $GLOBALS['log']->fatal('Failed creating a note and trying to attach it to a case from email');

       $GLOBALS['log']->fatal('File: bs_hook in ./custom/emails/bs_hook.php lines 88-123');

       $GLOBALS['log']->fatal($e->getMessage());

   }

   $GLOBALS['log']->info("Note was successful in being created from an email and attached to a case");

}

Best Regards

James Palmisano