AnsweredAssumed Answered

How to get related beans on a custom module's relationships

Question asked by James Palmisano on Jul 8, 2016
Latest reply on Nov 30, 2018 by Robert Sinclair

Hi,  I am running code similar to this:


//Load Account
$bean = BeanFactory::getBean('Accounts', $id);

//If relationship is loaded
if ($bean->load_relationship('contacts'))
   //Fetch related beans
   $relatedBeans = $bean->contacts->getBeans();


I got that from the sugar developer guide and I have created a API endpoint so this code will run when a url is invoked.


The project that I am working on has custom modules and when I write something similar to the code above it returns null which means there was no relationship found at all I think.


So the code I am running is :

$in_customer_bean = BeanFactory::getBean("IN_Customers",$customer_id);


        //$relatedBeans = false;


        //If relationship is loaded

        if ($in_customer_bean->load_relationship('in_locations')) {


            //Fetch related beans

            $relatedBeans = $in_customer_bean->in_locations->getBeans();

            return $relatedBeans;


and it just returns null. 


So with all custom modules created through the admin panel there are the two tables in_customers and in_locations and then there is a table to join the two called in_customers_in_locations_c.


Can you not do what I want to do with custom modules? Do I need to use SQL statement instead? Is that upgrade safe?


Comments appreciated