$countSameSpace
Counts how many other Spaces in the model share the same Space Number, and also returns their names. An extended variant of $countSameRooms that provides additional context for the error message.
Definition
$countSameSpace := function($spaceNumber, $spaceId){
{
"count": $count($spaces[values.number = $spaceNumber and id != $spaceId]),
"otherSpaces": $spaces[values.number = $spaceNumber and id != $spaceId].name
}
};
Dependencies
Requires $spaces in the outer scope:
$spaces := $[type = "Space"];
Parameters
| Parameter | Type | Description |
|---|---|---|
$spaceNumber |
string/number | The number of the space being checked |
$spaceId |
number | The id of the space being checked — excluded so a space does not count itself |
Return value
{
"count": 2,
"otherSpaces": ["Space 1.01 A", "Space 1.01 B"]
}
count is 0 when the number is unique. otherSpaces is an empty array in that case.
Difference from $countSameRooms
$countSameRooms returns only a number. $countSameSpace returns an object with both the count and the names of the conflicting spaces, so the error message can list them explicitly.
Usage
(
$spaces := $[type = "Space"];
$countSameSpace := function($spaceNumber, $spaceId){
{
"count": $count($spaces[values.number = $spaceNumber and id != $spaceId]),
"otherSpaces": $spaces[values.number = $spaceNumber and id != $spaceId].name
}
};
$[type = "Space"].{
"id": id,
"name": name,
"number": values.number,
"otherSpaces": $countSameSpace(values.number, id)
}
)
Validator: otherSpaces.count → int:LessThan 1
Used in rules
rule-7806ca49— Space number is uniek