//Load the relationship
$accountBean->load_relationship('cases');
//Can now call methods on the relationship object:
$casesIds = $accountBean->cases->get();
<?php
class LogicHook {
public function beforeSave($bean, $event, $arguments) {
if ($bean->fetched_row === false) {
if (!empty($bean->account_id)) {
$rel_name = 'account_cases'; // <- wrong | please use value from the 'name'=> parameter
if ($bean->load_relationship($rel_name)) {
$bean->$rel_name->add($bean->account_id);
}
}
}
}
}
?>
Could you please help understand what exactly is the requirement. There is one to many relationship between accounts and cases module. That is one account will have multiple cases associated with it. When we create a case for we select the account to for which the case is being recorded.
We have βcasesβ table which as account_id column which links the account with the case. You can query to get the cases for account (account_id) select account_id,name from cases where account_id = '{account_id}'; Replace {account_id} with actual account id to check the relationship.
It looks βacccounts_casesβ is not used because there is not many-to-many relationship between accounts and cases module.
Are you trying to create a new case record in the database table while saving or updating an account record.
Now, when we add account name, office number, email in the PDF template of Cases module. It is not displaying anything.
So, idea was to create before_save logic hook which will update relationship between case and account and eventually it will display in the downloaded PDF.