How to know relate field Join table name?

Hello,

I have Contact, Account & other custom module object. How to know relate field join table name using code?

I have Contact object relate field

Array
(
    [name] => account_name
    [rname] => name
    [id_name] => account_id
    [vname] => LBL_ACCOUNT_NAME
    [join_name] => accounts
    [type] => relate
    [link] => accounts
    [table] => accounts
    [isnull] => true
    [module] => Accounts
    [dbType] => varchar
    [len] => 255
    [source] => non-db
    [unified_search] => 1
    [populate_list] => Array
        (
            [billing_address_street] => primary_address_street
            [billing_address_city] => primary_address_city
            [billing_address_state] => primary_address_state
            [billing_address_postalcode] => primary_address_postalcode
            [billing_address_country] => primary_address_country
            [phone_office] => phone_work
        )

    [populate_confirm_label] => TPL_OVERWRITE_POPULATED_DATA_CONFIRM_WITH_MODULE_SINGULAR
    [importable] => true
    [exportable] => 1
    [export_link_type] => one
    [label] => Account Name
)

Other custom relate field.

Please any one advise me how to know run time relate field join table name?

Alan Apter Mehul  Bhandari Francesca Shiekh Ramana Raju Santhana

Thanks

Dipesh

Offshore Evolution Pvt Ltd

  • DEPRECATED - Does not work in 7.7.x

    I use this to get the relationship name 

    function getRelationshipByModules ($m1, $m2){
            global $db,$dictionary,$beanList;
            $rel = new Relationship;
            if($rel_info = $rel->retrieve_by_sides($m1, $m2, $db)){
                    $class = $beanList[$m1];
                    $bean = new $class();
                    $rel_name = $rel_info['relationship_name'];
                    foreach($bean->field_defs as $field=>$def){
                            if(isset($def['relationship']) && $def['relationship']==$rel_name) return(array($def['name'], $m1));
                    }
            }elseif($rel_info = $rel->retrieve_by_sides($m2, $m1, $db)){
                    $class = $beanList[$m2];
                    $bean = new $class();
                    $rel_name = $rel_info['relationship_name'];
                    foreach($bean->field_defs as $field=>$def){
                            if(isset($def['relationship']) && $def['relationship']==$rel_name) return(array($def['name'], $m2));
                    }
            }
            return(FALSE);
    }

    Which I then use to link/unlink two beans:

    function link_beans($bean1, $bean2, $options = array()){
       include_once('custom/entry_points/Utils/getRelationshipByModules.php');
       if(empty($bean1) || empty($bean2)) return(false);
       $m1 = $bean1->module_dir;
       $m2 = $bean2->module_dir;
       list($rel, $m) = getRelationshipByModules($m1, $m2);
       $GLOBALS['log']->debug($m1 . ',' . $m2);
       if($rel !== FALSE){
          if($m == $m1){
             $id = $bean1->id;
             $rel_id = $bean2->id;
          }elseif($m == $m2){
             $id = $bean2->id;
             $rel_id = $bean1->id;
          }
          $lhs = BeanFactory::retrieveBean($m, $id, array('disable_row_level_security' => true));
          $lhs->load_relationship($rel);
          if(!empty($options)){
             $lhs->$rel->add($rel_id, $options);
          }else{
             $lhs->$rel->add($rel_id);
          }
       }
       return;
    }
    function unlink_beans($bean1, $bean2){
       include_once('custom/entry_points/Utils/getRelationshipByModules.php');
       if(empty($bean1) || empty($bean2)) return(false);
       $m1 = $bean1->module_dir;
       $m2 = $bean2->module_dir;
       list($rel, $m) = getRelationshipByModules($m1, $m2);
       $GLOBALS['log']->debug($m1 . ',' . $m2);
       if($rel !== FALSE){
          if($m == $m1){
             $class = get_class($bean1);
             $id = $bean1->id;
             $rel_id = $bean2->id;
          }elseif($m == $m2){
             $class = get_class($bean2);
             $id = $bean2->id;
             $rel_id = $bean1->id;
          }
          $lhs = BeanFactory::retrieveBean($m, $id, array('disable_row_level_security' => true));
          $lhs->load_relationship($rel);
          $lhs->$rel->delete($id,$rel_id);
       }
       return;
    }

    HTH

    FrancescaS