From f72fbed6e17679044ac2d3863cfee1e3b43cffdf Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 24 Feb 2023 11:18:15 +0200 Subject: [PATCH] relation defs getConditions --- application/Espo/ORM/Defs/RelationDefs.php | 14 ++++++++++++++ tests/unit/Espo/ORM/DefsTest.php | 3 +++ 2 files changed, 17 insertions(+) diff --git a/application/Espo/ORM/Defs/RelationDefs.php b/application/Espo/ORM/Defs/RelationDefs.php index 470cb90b78..d853f22201 100644 --- a/application/Espo/ORM/Defs/RelationDefs.php +++ b/application/Espo/ORM/Defs/RelationDefs.php @@ -303,6 +303,20 @@ class RelationDefs return $list; } + /** + * Get additional middle table conditions. + * + * @return array + */ + public function getConditions(): array + { + if ($this->getType() !== Entity::MANY_MANY) { + throw new RuntimeException("Can't get conditions for non many-many relationship."); + } + + return $this->getParam('conditions') ?? []; + } + /** * Whether a parameter is set. */ diff --git a/tests/unit/Espo/ORM/DefsTest.php b/tests/unit/Espo/ORM/DefsTest.php index 41741c4967..6a07eafe45 100644 --- a/tests/unit/Espo/ORM/DefsTest.php +++ b/tests/unit/Espo/ORM/DefsTest.php @@ -178,6 +178,7 @@ class DefsTest extends \PHPUnit\Framework\TestCase 'relationName' => 'r2Name', 'midKeys' => ['k1', 'k2'], 'foreign' => 'f2', + 'conditions' => ['type' => 'Test'], ], ], ], @@ -212,6 +213,8 @@ class DefsTest extends \PHPUnit\Framework\TestCase $this->assertEquals('k1', $entityDefs->getRelation('r2')->getMidKey()); $this->assertEquals('k2', $entityDefs->getRelation('r2')->getForeignMidKey()); + + $this->assertEquals(['type' => 'Test'], $entityDefs->getRelation('r2')->getConditions()); } public function testRelationNotExisting()