Hello,
I have a record called Camera. It has a one to one relationship on it with a lens component. I want to create some history records when the lens is changed and I have created the following code from this forum topic:
But loadEntryLensHistory is being called on every update of the camera entity. I need it to only be called if the 1:1 relationship between the camera and the lens has changed. How can I identify this change? I have tried using the fetched methods and $entity->isFieldChanged - they don't seem to work and I don't think they are supposed to be used for relationships, however I can't find any other way to do it.
Cheers,
Clare
I have a record called Camera. It has a one to one relationship on it with a lens component. I want to create some history records when the lens is changed and I have created the following code from this forum topic:
PHP Code:
namespace Espo\Custom\Services;
use \Espo\ORM\Entity;
class Camera extends \Espo\Core\Templates\Services\Base
{
public function loadAdditionalFields(Entity $entity)
{
$GLOBALS['log']->debug('in camera service: loadAdditionalFields ');
parent::loadAdditionalFields($entity);
// do something here to find out if camera - lens relationship has changed
$this->loadEntryLensHistory($entity);
}
public function loadAdditionalFieldsForList(Entity $entity)
{
$GLOBALS['log']->debug('in camera service: loadAdditionalFieldsForList ');
}
protected function loadEntryLensHistory(Entity $entity)
{
// here I will create the history relationship between the camera and the lens
$GLOBALS['log']->debug('this fires for any change not just for camera-lens relationship change ');
}
}
Cheers,
Clare
Comment