From 109ee17a47650e0de5fa78dbd553b9b87e109052 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 14 Feb 2017 11:17:35 +0200 Subject: [PATCH] formula: parentName --- application/Espo/Core/Formula/AttributeFetcher.php | 9 ++++++++- .../Espo/Core/Utils/Database/Orm/Fields/LinkParent.php | 2 ++ application/Espo/ORM/Entity.php | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Formula/AttributeFetcher.php b/application/Espo/Core/Formula/AttributeFetcher.php index 3dc23d1a20..711ba7d4c3 100644 --- a/application/Espo/Core/Formula/AttributeFetcher.php +++ b/application/Espo/Core/Formula/AttributeFetcher.php @@ -1,4 +1,4 @@ -getAttributeParam($attribute, 'isParentName') && $methodName == 'get') { + $relationName = $entity->getAttributeParam($attribute, 'relation'); + if ($parent = $entity->get($relationName)) { + return $parent->get('name'); + } + } + return $entity->$methodName($attribute); } diff --git a/application/Espo/Core/Utils/Database/Orm/Fields/LinkParent.php b/application/Espo/Core/Utils/Database/Orm/Fields/LinkParent.php index 9657ff6b43..a84face77e 100644 --- a/application/Espo/Core/Utils/Database/Orm/Fields/LinkParent.php +++ b/application/Espo/Core/Utils/Database/Orm/Fields/LinkParent.php @@ -48,6 +48,8 @@ class LinkParent extends Base $fieldName.'Name' => array( 'type' => 'varchar', 'notStorable' => true, + 'relation' => $fieldName, + 'isParentName' => true ), ), ), diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php index 56fcdbbba6..105708737a 100644 --- a/application/Espo/ORM/Entity.php +++ b/application/Espo/ORM/Entity.php @@ -383,6 +383,11 @@ abstract class Entity implements IEntity return null; } + public function hasFetched($attributeName) + { + return array_key_exists($attributeName, $this->fetchedValuesContainer); + } + public function resetFetchedValues() { $this->fetchedValuesContainer = array();