1
0
Fork 0
mirror of synced 2024-07-06 15:11:21 +12:00

Merge remote-tracking branch 'origin/feat-relations-2' into feat-relations-2

This commit is contained in:
Jake Barnby 2023-03-27 12:18:29 +13:00
commit 9ac08b496b
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 43 additions and 1 deletions

View file

@ -1605,6 +1605,13 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
$attributes = $collection->getAttribute('attributes');
foreach ($attributes as &$attribute) {
$options = $attribute->getAttribute('options', []);
foreach ($options as $key => $option) {
$attribute->setAttribute($key, $option);
}
}
$response->dynamic(new Document([
'total' => \count($attributes),
'attributes' => $attributes

View file

@ -3277,6 +3277,21 @@ trait DatabasesBase
$this->assertEquals('relationship', $relation['body']['type']);
$this->assertEquals('processing', $relation['body']['status']);
$attributes = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/attributes', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]));
$this->assertEquals(200, $attributes['headers']['status-code']);
$this->assertEquals(2, $attributes['body']['total']);
$attributes = $attributes['body']['attributes'];
$this->assertEquals('library', $attributes[1]['relatedCollection']);
$this->assertEquals('oneToOne', $attributes[1]['relationType']);
$this->assertEquals(false, $attributes[1]['twoWay']);
$this->assertEquals('person', $attributes[1]['twoWayKey']);
$this->assertEquals(Database::RELATION_MUTATE_CASCADE, $attributes[1]['onDelete']);
$attribute = $this->client->call(Client::METHOD_GET, "/databases/{$databaseId}/collections/{$person['body']['$id']}/attributes/library", array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -3574,7 +3589,6 @@ trait DatabasesBase
'key' => 'artist',
'twoWayKey' => 'albums',
]);
$this->assertEquals(202, $response['headers']['status-code']);
$this->assertEquals('artist', $response['body']['key']);
$this->assertEquals('relationship', $response['body']['type']);
@ -3641,6 +3655,27 @@ trait DatabasesBase
$this->assertEquals('Album 1', $artist['body']['albums'][0]['name']);
$this->assertEquals($permissions, $artist['body']['albums'][0]['$permissions']);
// Update disable 2 way
$relation = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $albums['body']['$id'] . '/attributes/artist/relationship', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'twoWay' => false,
]);
$this->assertEquals(202, $response['headers']['status-code']);
$artist = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $artists['body']['$id'] . '/documents/' . $album['body']['artist']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $artist['headers']['status-code']);
$this->assertEquals('Artist 1', $artist['body']['name']);
$this->assertEquals($permissions, $artist['body']['$permissions']);
$this->assertArrayNotHasKey("albums", $artist['body']);
return [
'databaseId' => $databaseId,
'albumsCollection' => $albums['body']['$id'],