duanjuelian4640 2015-03-13 11:40
浏览 56
已采纳

我在哪里可以找到SugarCRM中默认关系的名称?

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?

  • 写回答

1条回答 默认 最新

  • douba8048 2015-03-13 21:25
    关注

    The easiest single source is to look into the cache directory because this merges all custom and out-of-the-box fields and relationships into one big array. To see all relationships from an Account perspective, check cache/modules/Accounts/Accountsvardefs.php and look for the relationships key and any fields where the type parameter is link. You'll find "stock" relationships like contacts and opportunities as well any and all custom relationships are built into that array.

    Note that custom relationships will be called different things depending on the object you're working with. For example, a custom one-to-many relationships between custom modules Meals and Ingredients might be named key_meals_ingredients_meals on the Meals side and key_meals_ingredients_ingredients on the Ingredients side.

    You can also find these in the user interface using Studio. Navigate into Studio, then your module, then into the Relationships table. The Name column on the left of the Relationships table is the value you're after.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)