convert relatedOptions to options
This commit is contained in:
parent
c1bce185fd
commit
44de884ee5
4 changed files with 23 additions and 24 deletions
|
@ -68,7 +68,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
|
|||
$formatOptions = $attribute->getAttribute('formatOptions', []);
|
||||
$filters = $attribute->getAttribute('filters', []); // filters are hidden from the endpoint
|
||||
$default = $attribute->getAttribute('default');
|
||||
$relationshipOptions = $attribute->getAttribute('relationshipOptions', []);
|
||||
$options = $attribute->getAttribute('options', []);
|
||||
|
||||
$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) {
|
||||
$relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $relationshipOptions['relatedCollection']);
|
||||
$relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
|
||||
if ($relatedCollection->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
|
|||
'format' => $format,
|
||||
'formatOptions' => $formatOptions,
|
||||
'filters' => $filters,
|
||||
'relationshipOptions' => $relationshipOptions,
|
||||
'options' => $options,
|
||||
]);
|
||||
|
||||
$dbForProject->checkAttribute($collection, $attribute);
|
||||
|
@ -1394,7 +1394,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati
|
|||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
'relationshipOptions' => [
|
||||
'options' => [
|
||||
'relatedCollection' => $relatedCollectionId,
|
||||
'relationType' => $type,
|
||||
'twoWay' => $twoWay,
|
||||
|
@ -1409,17 +1409,14 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati
|
|||
$events
|
||||
);
|
||||
|
||||
$options = $attribute->getAttribute('relationshipOptions', []);
|
||||
|
||||
if (!empty($options)) {
|
||||
$attribute->setAttribute('relatedCollection', $options['relatedCollection']);
|
||||
$attribute->setAttribute('relationType', $options['relationType']);
|
||||
$attribute->setAttribute('twoWay', $options['twoWay']);
|
||||
$attribute->setAttribute('twoWayKey', $options['twoWayKey']);
|
||||
$attribute->setAttribute('onUpdate', $options['onUpdate']);
|
||||
$attribute->setAttribute('onDelete', $options['onDelete']);
|
||||
$attribute->setAttribute('side', $options['side']);
|
||||
}
|
||||
$options = $attribute->getAttribute('options', []);
|
||||
$attribute->setAttribute('relatedCollection', $options['relatedCollection'] || null);
|
||||
$attribute->setAttribute('relationType', $options['relationType'] || null);
|
||||
$attribute->setAttribute('twoWay', $options['twoWay'] || null);
|
||||
$attribute->setAttribute('twoWayKey', $options['twoWayKey'] || null);
|
||||
$attribute->setAttribute('onUpdate', $options['onUpdate'] || null);
|
||||
$attribute->setAttribute('onDelete', $options['onDelete'] || null);
|
||||
$attribute->setAttribute('side', $options['side'] || null);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
|
|
|
@ -91,22 +91,22 @@ class DatabaseV1 extends Worker
|
|||
$format = $attribute->getAttribute('format', '');
|
||||
$formatOptions = $attribute->getAttribute('formatOptions', []);
|
||||
$filters = $attribute->getAttribute('filters', []);
|
||||
$relationshipOptions = $attribute->getAttribute('relationshipOptions', []);
|
||||
$options = $attribute->getAttribute('options', []);
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
try {
|
||||
if ($type === Database::VAR_RELATIONSHIP) {
|
||||
$relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $relationshipOptions['relatedCollection']);
|
||||
$relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']);
|
||||
if (
|
||||
!$dbForProject->createRelationship(
|
||||
collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
|
||||
relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(),
|
||||
type: $relationshipOptions['relationType'],
|
||||
twoWay: $relationshipOptions['twoWay'],
|
||||
id: $relationshipOptions['id'],
|
||||
twoWayKey: $relationshipOptions['twoWayKey'],
|
||||
onUpdate: $relationshipOptions['onUpdate'],
|
||||
onDelete: $relationshipOptions['onDelete'],
|
||||
type: $options['relationType'] || null,
|
||||
twoWay: $options['twoWay'] || null,
|
||||
id: $options['id'] || null,
|
||||
twoWayKey: $options['twoWayKey'] || null,
|
||||
onUpdate: $options['onUpdate'] || null,
|
||||
onDelete: $options['onDelete'] || null,
|
||||
)
|
||||
) {
|
||||
throw new Exception('Failed to create Attribute');
|
||||
|
|
|
@ -83,6 +83,7 @@ services:
|
|||
- ./docs:/usr/src/code/docs
|
||||
- ./public:/usr/src/code/public
|
||||
- ./src:/usr/src/code/src
|
||||
- ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework
|
||||
depends_on:
|
||||
- mariadb
|
||||
- redis
|
||||
|
@ -344,6 +345,7 @@ services:
|
|||
- ./app:/usr/src/code/app
|
||||
- ./src:/usr/src/code/src
|
||||
#- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
- ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework
|
||||
depends_on:
|
||||
- redis
|
||||
- mariadb
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
stopOnFailure="true"
|
||||
>
|
||||
<extensions>
|
||||
<extension class="Appwrite\Tests\TestHook" />
|
||||
|
|
Loading…
Reference in a new issue