fill primary account on selecting from account

This commit is contained in:
yuri
2016-08-30 15:30:06 +03:00
parent 4a40f1fba7
commit e53aff0031
@@ -41,5 +41,25 @@ class Account extends \Espo\Core\ORM\Repositories\RDB
$this->relate($entity, 'targetLists', $entity->get('targetListId'));
}
}
protected function afterRelateContacts(Entity $entity, $foreign, $data)
{
if (!($foreign instanceof Entity)) return;
if (!$foreign->get('accountId')) {
$foreign->set('accountId', $entity->id);
$this->getEntityManager()->saveEntity($foreign);
}
}
protected function afterUnrelateContacts(Entity $entity, $foreign, $data)
{
if (!($foreign instanceof Entity)) return;
if ($foreign->get('accountId') && $foreign->get('accountId') === $entity->id) {
$foreign->set('accountId', null);
$this->getEntityManager()->saveEntity($foreign);
}
}
}