From 7d261310193d9bb8c5cc4f85c475518eab6e33ec Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 3 Dec 2025 21:19:53 +1300 Subject: [PATCH] Validate other relationship options --- .../Utopia/Database/Validator/Attributes.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Appwrite/Utopia/Database/Validator/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Attributes.php index fafa1d0f8e..48339bc642 100644 --- a/src/Appwrite/Utopia/Database/Validator/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Attributes.php @@ -183,6 +183,30 @@ class Attributes extends Validator $this->message = "Relationship attribute '" . $attribute['key'] . "' must have valid 'relationType'"; return false; } + + // Validate twoWay if provided + if (isset($attribute['twoWay']) && !is_bool($attribute['twoWay'])) { + $this->message = "Invalid 'twoWay' value for relationship attribute '" . $attribute['key'] . "': must be a boolean"; + return false; + } + + // Validate twoWayKey if provided + if (isset($attribute['twoWayKey']) && !empty($attribute['twoWayKey'])) { + if (!$keyValidator->isValid($attribute['twoWayKey'])) { + $this->message = "Invalid 'twoWayKey' for relationship attribute '" . $attribute['key'] . "': " . $keyValidator->getDescription(); + return false; + } + } + + // Validate onDelete if provided + if (isset($attribute['onDelete']) && !in_array($attribute['onDelete'], [ + Database::RELATION_MUTATE_CASCADE, + Database::RELATION_MUTATE_RESTRICT, + Database::RELATION_MUTATE_SET_NULL, + ])) { + $this->message = "Invalid 'onDelete' value for relationship attribute '" . $attribute['key'] . "': must be 'cascade', 'restrict', or 'setNull'"; + return false; + } } }