relation defs getConditions
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user