AnsweredAssumed Answered

does it matter which bean you call load_relationship() from in the relationship?

Question asked by Shannon Warren on Jun 12, 2017
Latest reply on Jun 15, 2017 by Shannon Warren

ondemand 7.8

I have a before_save logic hook on Leads and I have a relationship to a custom module cbsa.

 

When I create a new lead and try to get the load_relationship('cbsal_cbsa_leads_1') so that I can do

 

$bean->cbsal_cbsa_leads_1->add my code fails .. but if I call

$bean2->load_relationship('cbsal_cbsa_leads_1') off of a query for the cbsa table my code works. Is there a requirement on which side of the bean relationship you call load_relationship from, or am I doing something wrong? this is a new lead with no related record at creation.

 

 

This does not work and fails with error

      $sugarQuery = new SugarQuery();
        $sugarQuery->from(BeanFactory::getBean('cbsal_CBSA'), array('team_security' => false));
        //$sugarQuery->select(array('id');
        $sugarQuery->select();
        $sugarQuery->where()->queryAnd()->equals('state', $long_state)->equals('county', $county);
        $result = $sugarQuery->execute();
       
         $bean2 = BeanFactory::getBean('cbsal_CBSA', $result[0]['id']);

 

        $bean->load_relationship('cbsal_cbsa_leads_1');   // false at this part even with next line commented out.
       // $bean->cbsal_cbsa_leads_1->add(bean2->id);
This executes with now error:
        $sugarQuery = new SugarQuery();
        $sugarQuery->from(BeanFactory::getBean('cbsal_CBSA'), array('team_security' => false));
        //$sugarQuery->select(array('id');
        $sugarQuery->select();
        $sugarQuery->where()->queryAnd()->equals('state', $long_state)->equals('county', $county);
        $result = $sugarQuery->execute();
       
         $bean2 = BeanFactory::getBean('cbsal_CBSA', $result[0]['id']);

 

        $bean2->load_relationship('cbsal_cbsa_leads_1'); //this passes with no error
       // $bean->cbsal_cbsa_leads_1->add(bean2->id);
my relationship from studio is attached.

Outcomes