I am writing logic hook and I need to update 1 module fields by using other module elements.
<?php
class logic_hooks_class {
function after_save_method($bean, $event, $arguments) {
if (!isset($bean->ignore_update_c)||$bean->ignore_update_c === false {
//here I need to get module's reservations element: amount_reserved
//should I load relationship like $bean->load_relationship('reservations'); ??
//need to set total_reserved = amount_reserved;
//by the way amount_reserved might have several values for one reserved
$bean->goods = $bean->amount-$bean->total_reserved;
$bean->ignore_update_c = true;
$bean->save();
}
}
}
?>
You can load the beans for the relationship like this:
$bean->load_relationship('reservations');
$reservations = $bean->reservations->getBeans();
Now one can loop the $reservations
and fetch
and sum up the wanted value.
Just to clarify how load_relationship
works. The parameter for load_relationship
should be the link vardef pointing to the name of the relationship. A logical name is the plural name for the module, like reservations.