I've been stuck a while because in a Cases logic hook I couldn't load contacts_cases relationship as I did with another custom relationship, like this:
$bean->load_relationship('cases_lines');
$lines = $bean->cases_lines->getBeans();
$bean->load_relationship('contacts_cases');
$contacts->$bean->contacts_cases->getBeans();
The first was working, the latter wasn't.
I found out that I was using the wrong name because it's a default relationship and its name is 'contacts' and not 'contacts_cases' as I supposed, so I change my code like this:
$bean->load_relationship('contacts');
$contacts->$bean->contacts->getBeans();
and now it's working perfectly.
I didn't found in documentation the naming difference between default and custom relationship, I found the solution above only debugging SugarBean method 'load_relationship' and printing out the loaded relationships.
This line of code
error_log('LOADED RELATIONSHIPS '.print_r($this->loaded_relationships, true));
printed out
Array
(
[0] => cases_lines
[1] => contacts
)
In Studio the relationship appears as 'contacts_cases', the only place where I found the name 'contacts' is in file modules/Cases/vardefs.php
'contacts' =>
array (
'name' => 'contacts',
'type' => 'link',
'relationship' => 'contacts_cases',
'source'=>'non-db',
'vname'=>'LBL_CONTACTS',
),
Also in relationships table the relationship_name is 'contacts_cases'.
Is there any place where I can see the real names that I must use when calling load_relationship or the only solution is looking in vardefs?