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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?