1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00

convert relatedOptions to options

This commit is contained in:
fogelito 2023-03-16 09:31:48 +02:00
parent c1bce185fd
commit 44de884ee5
4 changed files with 23 additions and 24 deletions

View file

@ -68,7 +68,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
$formatOptions = $attribute->getAttribute('formatOptions', []); $formatOptions = $attribute->getAttribute('formatOptions', []);
$filters = $attribute->getAttribute('filters', []); // filters are hidden from the endpoint $filters = $attribute->getAttribute('filters', []); // filters are hidden from the endpoint
$default = $attribute->getAttribute('default'); $default = $attribute->getAttribute('default');
$relationshipOptions = $attribute->getAttribute('relationshipOptions', []); $options = $attribute->getAttribute('options', []);
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
@ -98,7 +98,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
} }
if ($type === Database::VAR_RELATIONSHIP) { if ($type === Database::VAR_RELATIONSHIP) {
$relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $relationshipOptions['relatedCollection']); $relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
if ($relatedCollection->isEmpty()) { if ($relatedCollection->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND); throw new Exception(Exception::COLLECTION_NOT_FOUND);
} }
@ -122,7 +122,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
'format' => $format, 'format' => $format,
'formatOptions' => $formatOptions, 'formatOptions' => $formatOptions,
'filters' => $filters, 'filters' => $filters,
'relationshipOptions' => $relationshipOptions, 'options' => $options,
]); ]);
$dbForProject->checkAttribute($collection, $attribute); $dbForProject->checkAttribute($collection, $attribute);
@ -1394,7 +1394,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati
'default' => null, 'default' => null,
'array' => false, 'array' => false,
'filters' => [], 'filters' => [],
'relationshipOptions' => [ 'options' => [
'relatedCollection' => $relatedCollectionId, 'relatedCollection' => $relatedCollectionId,
'relationType' => $type, 'relationType' => $type,
'twoWay' => $twoWay, 'twoWay' => $twoWay,
@ -1409,17 +1409,14 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati
$events $events
); );
$options = $attribute->getAttribute('relationshipOptions', []); $options = $attribute->getAttribute('options', []);
$attribute->setAttribute('relatedCollection', $options['relatedCollection'] || null);
if (!empty($options)) { $attribute->setAttribute('relationType', $options['relationType'] || null);
$attribute->setAttribute('relatedCollection', $options['relatedCollection']); $attribute->setAttribute('twoWay', $options['twoWay'] || null);
$attribute->setAttribute('relationType', $options['relationType']); $attribute->setAttribute('twoWayKey', $options['twoWayKey'] || null);
$attribute->setAttribute('twoWay', $options['twoWay']); $attribute->setAttribute('onUpdate', $options['onUpdate'] || null);
$attribute->setAttribute('twoWayKey', $options['twoWayKey']); $attribute->setAttribute('onDelete', $options['onDelete'] || null);
$attribute->setAttribute('onUpdate', $options['onUpdate']); $attribute->setAttribute('side', $options['side'] || null);
$attribute->setAttribute('onDelete', $options['onDelete']);
$attribute->setAttribute('side', $options['side']);
}
$response $response
->setStatusCode(Response::STATUS_CODE_ACCEPTED) ->setStatusCode(Response::STATUS_CODE_ACCEPTED)

View file

@ -91,22 +91,22 @@ class DatabaseV1 extends Worker
$format = $attribute->getAttribute('format', ''); $format = $attribute->getAttribute('format', '');
$formatOptions = $attribute->getAttribute('formatOptions', []); $formatOptions = $attribute->getAttribute('formatOptions', []);
$filters = $attribute->getAttribute('filters', []); $filters = $attribute->getAttribute('filters', []);
$relationshipOptions = $attribute->getAttribute('relationshipOptions', []); $options = $attribute->getAttribute('options', []);
$project = $dbForConsole->getDocument('projects', $projectId); $project = $dbForConsole->getDocument('projects', $projectId);
try { try {
if ($type === Database::VAR_RELATIONSHIP) { if ($type === Database::VAR_RELATIONSHIP) {
$relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $relationshipOptions['relatedCollection']); $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']);
if ( if (
!$dbForProject->createRelationship( !$dbForProject->createRelationship(
collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(),
type: $relationshipOptions['relationType'], type: $options['relationType'] || null,
twoWay: $relationshipOptions['twoWay'], twoWay: $options['twoWay'] || null,
id: $relationshipOptions['id'], id: $options['id'] || null,
twoWayKey: $relationshipOptions['twoWayKey'], twoWayKey: $options['twoWayKey'] || null,
onUpdate: $relationshipOptions['onUpdate'], onUpdate: $options['onUpdate'] || null,
onDelete: $relationshipOptions['onDelete'], onDelete: $options['onDelete'] || null,
) )
) { ) {
throw new Exception('Failed to create Attribute'); throw new Exception('Failed to create Attribute');

View file

@ -83,6 +83,7 @@ services:
- ./docs:/usr/src/code/docs - ./docs:/usr/src/code/docs
- ./public:/usr/src/code/public - ./public:/usr/src/code/public
- ./src:/usr/src/code/src - ./src:/usr/src/code/src
- ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework
depends_on: depends_on:
- mariadb - mariadb
- redis - redis
@ -344,6 +345,7 @@ services:
- ./app:/usr/src/code/app - ./app:/usr/src/code/app
- ./src:/usr/src/code/src - ./src:/usr/src/code/src
#- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database #- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
- ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework
depends_on: depends_on:
- redis - redis
- mariadb - mariadb

View file

@ -6,7 +6,7 @@
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="true"
> >
<extensions> <extensions>
<extension class="Appwrite\Tests\TestHook" /> <extension class="Appwrite\Tests\TestHook" />