SugarCRM can't access a relation of two modules

1.2k views Asked by At

So im going nuts here, I might as well tell you the whole thing i did, and maybe you can help me with it.

I am in the on demand version of sugar.

i need to relate 2 custom modules so i used the module builder to create a package for them:

enter image description here

the custom modules are form and map. then i created a relationship between both like this:

enter image description here

After that i deployed my package to my sugar instance and proceeded to create some test data.

enter image description here

then on my custom entry point i wish to get the maps related to a specific form so this is my code:

enter image description here

But when i try to call my entry point It wont return any maps related to the form, here is an example:

Inline image 6

in the example the maps arent echoed, i just cant find where the problem is. any help would be appreciated !

1

There are 1 answers

1
Hakulukiam On

I too have had problems with load_relationship. In most cases the problem ist the $rel_map param in your case. There is a Sugar function in modules/Leads/views/view.convertleads.php:

protected function findRelationship(
    $from,
    $to
    )
{
    global $dictionary;
    require_once("modules/TableDictionary.php");
    foreach ($from->field_defs as $field=>$def)
    {
        if (isset($def['type']) && $def['type'] == "link" && isset($def['relationship'])) 
        {
            $rel_name = $def['relationship'];
            $rel_def = "";
            if (isset($dictionary[$from->object_name]['relationships']) && isset($dictionary[$from->object_name]['relationships'][$rel_name]))
            {
                $rel_def = $dictionary[$from->object_name]['relationships'][$rel_name];
            }
            else if (isset($dictionary[$to->object_name]['relationships']) && isset($dictionary[$to->object_name]['relationships'][$rel_name]))
            {
                $rel_def = $dictionary[$to->object_name]['relationships'][$rel_name];
            }
            else if (isset($dictionary[$rel_name]) && isset($dictionary[$rel_name]['relationships'])
                    && isset($dictionary[$rel_name]['relationships'][$rel_name]))
            {
                $rel_def = $dictionary[$rel_name]['relationships'][$rel_name];
            }
            if (!empty($rel_def)) {
                if ($rel_def['lhs_module'] == $from->module_dir && $rel_def['rhs_module'] == $to->module_dir )
                {
                    return $field;
                }
                else if ($rel_def['rhs_module'] == $from->module_dir && $rel_def['lhs_module'] == $to->module_dir )
                {
                    return $field;
                }
            }
        }
    }
    return false;
}

It returns the required Value for load_relationship if given a bean of each module as param. In the code '$def['type'] == "link"' you can see it fetches the link and NOT the relation.

In short: get the linkname for your relation in your d_form module to use in load_relationship not the relationship name