mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Extract model options
This commit is contained in:
@@ -1569,13 +1569,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/relati
|
||||
);
|
||||
|
||||
$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);
|
||||
|
||||
foreach ($options as $key => $option) {
|
||||
$attribute->setAttribute($key, $option);
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
|
||||
@@ -1673,6 +1670,11 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key')
|
||||
// Select response model based on type and format
|
||||
$type = $attribute->getAttribute('type');
|
||||
$format = $attribute->getAttribute('format');
|
||||
$options = $attribute->getAttribute('options', []);
|
||||
|
||||
foreach ($options as $key => $option) {
|
||||
$attribute->setAttribute($key, $option);
|
||||
}
|
||||
|
||||
$model = match ($type) {
|
||||
Database::VAR_RELATIONSHIP => Response::MODEL_ATTRIBUTE_RELATIONSHIP,
|
||||
|
||||
@@ -27,22 +27,43 @@ class AttributeRelationship extends Attribute
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Default value for attribute when not provided. Only null is optional',
|
||||
'default' => null,
|
||||
'example' => '',
|
||||
])
|
||||
->addRule('relatedCollection', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The Id of the related collection',
|
||||
'default' => null,
|
||||
'example' => 'collection',
|
||||
])
|
||||
->addRule('relationType', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The type of the relationship ',
|
||||
'default' => null,
|
||||
'example' => 'oneToOne|oneToMany|manyToOne|manyToMany',
|
||||
])
|
||||
->addRule('twoWay', [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Is the relationship going two ways?',
|
||||
'default' => null,
|
||||
'example' => 'relationship',
|
||||
])
|
||||
->addRule('options', [
|
||||
'type' => [
|
||||
'relatedCollection',
|
||||
'relationType',
|
||||
'twoWay',
|
||||
'twoWayKey',
|
||||
'onUpdate',
|
||||
'onDelete',
|
||||
'side',
|
||||
],
|
||||
'description' => 'Options attributes.',
|
||||
'default' => [],
|
||||
'example' => new \stdClass(),
|
||||
'array' => true,
|
||||
->addRule('twoWayKey', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The key of the 2 way relationship',
|
||||
'default' => null,
|
||||
'example' => 'string',
|
||||
])
|
||||
->addRule('onUpdate', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'How to set related documents after parent document is updated',
|
||||
'default' => null,
|
||||
'example' => 'restrict|cascade|setNull',
|
||||
])
|
||||
->addRule('onDelete', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'How to set related documents after parent document is deleted',
|
||||
'default' => null,
|
||||
'example' => 'restrict|cascade|setNull',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -317,11 +317,11 @@ trait DatabasesBase
|
||||
$this->assertEquals('relationship', $attribute['body']['type']);
|
||||
$this->assertEquals(false, $attribute['body']['required']);
|
||||
$this->assertEquals(false, $attribute['body']['array']);
|
||||
$this->assertEquals('oneToOne', $attribute['body']['options']['relationType']);
|
||||
$this->assertEquals(false, $attribute['body']['options']['twoWay']);
|
||||
$this->assertEquals('cascade', $attribute['body']['options']['onUpdate']);
|
||||
$this->assertEquals('restrict', $attribute['body']['options']['onDelete']);
|
||||
$this->assertEquals('libraryId', $attribute['body']['options']['id']);
|
||||
$this->assertEquals('oneToOne', $attribute['body']['relationType']);
|
||||
$this->assertEquals(false, $attribute['body']['twoWay']);
|
||||
$this->assertEquals('cascade', $attribute['body']['onUpdate']);
|
||||
$this->assertEquals('restrict', $attribute['body']['onDelete']);
|
||||
//$this->assertEquals('libraryId', $attribute['body']['id']); //
|
||||
|
||||
$person1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -356,7 +356,6 @@ trait DatabasesBase
|
||||
$this->assertEquals(1, $documents['body']['total']);
|
||||
$this->assertEquals('Library 1', $documents['body']['documents'][0]['libraryId']['libraryName']);
|
||||
|
||||
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -371,13 +370,10 @@ trait DatabasesBase
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
var_dump($response);
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
|
||||
die;
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user