Studioを使用するMeetingsモジュールで、1対多の関係をAccountモジュールに追加しました。会議エントリを保存し、アカウントを使用して関連エントリを追加すると、関連するアカウントの詳細がアカウントサブパネルに表示されません。最新バージョンのSugarCRMを使用しています。
前もって感謝します。
目的の結果を達成するためのロジックフックを作成します。
custom / modules / Meetings / logic_hooks.php
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'Set Account relationship', 'custom/modules/Meetings/AccountRelationshipHook.php', 'AccountRelationshipHook', 'setAccountRelationship');
$hook_array['before_delete'] = Array();
$hook_array['before_delete'][] = Array(1, 'Remove Account relationship', 'custom/modules/Meetings/AccountRelationshipHook.php', 'AccountRelationshipHook', 'deleteAccountRelationship');
次に、ロジックフックで、新しく定義された関係'meetings_accounts'(または名前を付けたもの)を使用するメソッドを作成し、アカウントレコードを追加または削除します。1対多なので、会議レコードごとにアカウントが1つだけであることを確認する必要があります。また、整理整頓のために、会議が削除されたら、メソッドdeleteAccountRelationship()を使用してレコードの関係も削除します。
custom / modules / Meetings / AccountRelationshipHook.php
class AccountRelationshipHook {
public function setAccountRelationship(&$bean, $event, $arguments) {
if ($bean->parent_type == 'Accounts') {
$bean->load_relationship('meetings_accounts');
if ($bean->parent_id != $bean->fetched_row['parent_id']) {
$bean->meetings_accounts->delete($bean->id, $bean->fetched_row['parent_id']);
}
$bean->meetings_accounts->add($bean->parent_id);
}
}
public function deleteAccountRelationship(&$bean, $event, $arguments) {
if ($bean->parent_type == 'Accounts') {
$bean->load_relationship('meetings_accounts');
$bean->meetings_accounts->delete($bean->id, $bean->parent_id);
}
}
}