Cool function to relate beans together automatically.

John Mertic —  November 6, 2013 — 2 Comments

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. (
https://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-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 😉

Thanks,
Francesca

John Mertic

Posts

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.

2 responses to Cool function to relate beans together automatically.

  1. 
    Francesca Shiekh March 18, 2014 at 1:55 pm

    replace
    $class = $bean1->object_name;
    &
    $class = $bean2->object_name;
    with
    $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.

  2. 
    Francesca Shiekh January 18, 2017 at 2:04 pm

    DEPRECATED – Does not work in 7.7.x

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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