Cool function to relate beans together automatically.

John Mertic —  November 6, 2013 — 1 Comment

Editor’s Note: This post came from Sugar Community member Francesca Shiekh. Thanks Francesca!

In a previous post I shared a function that will find the relationship name for two modules. ( )

As I was importing some salesforce records into an existing implementation of SugarCRM I found myself needing to relate beans again and again.

So I created a function to link two beans. Given two beans, it looks up the relationship between them, if one is found then it links the two beans:

Hope this can be of use to others. Or if there is a better way to handle this let me know😉


John Mertic


John Mertic manages the strategic ISV alliances program for SugarCRM, having several years of techincal experience bringing solutions to market with several SugarCRM technology partners. A frequent conference speaker and an avid writer, he has been published in php|architect, IBM Developerworks, and in the Apple Developer Connection, and is the author of the book 'The Definitive Guide to SugarCRM: Better Business Applications' and the book 'Building on SugarCRM: Creating Applications the Easy Way'. He is also president of the OpenSocial foundation, guiding them in solving interoperability issues for enterprise application providers worldwide.

One response to Cool function to relate beans together automatically.

    Francesca Shiekh March 18, 2014 at 1:55 pm

    $class = $bean1->object_name;
    $class = $bean2->object_name;
    $class = get_class($bean1);
    $class = get_class($bean2);
    respectively, or it won’t work for modules like Cases where the class is not Case but aCase.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s