relation defs getConditions

This commit is contained in:
Yuri Kuznetsov
2023-02-24 11:18:15 +02:00
parent 56fe4e2ef7
commit f72fbed6e1
2 changed files with 17 additions and 0 deletions
@@ -303,6 +303,20 @@ class RelationDefs
return $list;
}
/**
* Get additional middle table conditions.
*
* @return array<string, ?scalar>
*/
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.
*/
+3
View File
@@ -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()