diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 6b96595122..6c29937d20 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -123,7 +123,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'format' => $format, 'formatOptions' => $formatOptions, 'filters' => $filters, - 'options' => $options, // Do we want all of the options? + 'options' => $options, // Do we want all options? ]); $dbForProject->checkAttribute($collection, $attribute); diff --git a/app/workers/databases.php b/app/workers/databases.php index 71e78b3777..e18c3e1d27 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -4,6 +4,7 @@ use Appwrite\Event\Event; use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Resque\Worker; use Utopia\CLI\Console; +use Utopia\Database\Database; use Utopia\Database\Document; require_once __DIR__ . '/../init.php'; @@ -73,7 +74,7 @@ class DatabaseV1 extends Worker 'collectionId' => $collection->getId(), 'attributeId' => $attribute->getId() ]); - /** + /**x * Fetch attribute from the database, since with Resque float values are loosing informations. */ $attribute = $dbForProject->getDocument('attributes', $attribute->getId()); @@ -89,12 +90,29 @@ class DatabaseV1 extends Worker $format = $attribute->getAttribute('format', ''); $formatOptions = $attribute->getAttribute('formatOptions', []); $filters = $attribute->getAttribute('filters', []); + $options = $attribute->getAttribute('options', []); $project = $dbForConsole->getDocument('projects', $projectId); try { - if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { + if ($type === Database::VAR_RELATIONSHIP) { + if ( + !$dbForProject->createRelationship( + collection: 'make', + relatedCollection: 'model', + type: $options['type'], + twoWay: $options['twoWay'], + id: $options['id'], + twoWayKey: $options['twoWayKey'], + onUpdate: $options['onUpdate'], + onDelete: $options['onDelete'], + ) + ) { + throw new Exception('Failed to create Attribute'); + } + } elseif (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { throw new Exception('Failed to create Attribute'); } + $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage());