Editor’s Note: This post came from Sugar Community member Francesca Shiekh. Thanks Francesca!
I often find myself referencing Jeff Bickart’s “HOWTO: Using the bean instead of SQL all the time.” (http://developers.sugarcrm.com/wordpress/2012/03/23/howto-using-the-bean-instead-of-sql-all-the-time/ )
But when it comes to using the tips in “Adding and removing related records” finding the right relationship name is always a challenge (it is NOT the relationship_name field in the relationship table!).
Also, I sometimes need to find that relationship name programmatically based on module names.
To address this problem I created the following function which, given two module names, returns the name of the relationship needed to load, add and delete relationships between records. If there is no relationship between the modules the function returns FALSE.