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.

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

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况