Skip to content

Commit 92c1b73

Browse files
committed
check relation multiplicity when adding to a relation
1 parent a0d5e8f commit 92c1b73

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/wcmf/lib/model/Node.php

+6
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ public function addNode(PersistentObject $other, $role=null, $forceSet=false, $t
326326
$oldValue = parent::getValue($role);
327327
$addedNodes = []; // this array contains the other node or nothing
328328
if (!$relDesc || $relDesc->isMultiValued()) {
329+
// check multiplicity if multivalued
330+
$maxMultiplicity = $relDesc->getOtherMaxMultiplicity();
331+
if ($relDesc->isMultiValued() && !($maxMultiplicity == 'unbounded') &&
332+
sizeof(oldValue) >= $maxMultiplicity) {
333+
throw new IllegalArgumentException("Maximum number of related objects exceeded: ".$role." (".(sizeof(oldValue)+1)." > ".$maxMultiplicity.")");
334+
}
329335
// make sure that the value is an array if multivalued
330336
$mergeResult = self::mergeObjectLists($oldValue, [$value]);
331337
$value = $mergeResult['result'];

0 commit comments

Comments
 (0)