mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Fix hardcoded collectionId
This commit is contained in:
+1
-2
@@ -29,7 +29,6 @@ abstract class Action extends AppwriteAction
|
||||
} else {
|
||||
$this->removableAttributes = ['$databaseId', '$collectionId'];
|
||||
}
|
||||
|
||||
return parent::setHttpPath($path);
|
||||
}
|
||||
|
||||
@@ -232,7 +231,7 @@ abstract class Action extends AppwriteAction
|
||||
$collectionId = $collection->getId();
|
||||
$document->removeAttribute('$collection');
|
||||
$document->setAttribute('$databaseId', $database->getId());
|
||||
$document->setAttribute('$collectionId', $collectionId);
|
||||
$document->setAttribute('$' . $this->getCollectionsEventsContext() . 'Id', $collectionId);
|
||||
|
||||
$relationships = $collectionsCache[$collectionId] ??= \array_filter(
|
||||
$collection->getAttribute('attributes', []),
|
||||
|
||||
@@ -5245,6 +5245,55 @@ trait DatabasesBase
|
||||
$this->assertArrayNotHasKey('libraries', $response['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOneToManyRelationship
|
||||
*/
|
||||
public function testCollectionIdAttributeConsistency(array $data): void
|
||||
{
|
||||
// Test that when NO select query is used, $collectionId is present (not $tableId)
|
||||
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['personCollection'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('fullName', ['Stevie Wonder'])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(1, $response['body']['documents']);
|
||||
|
||||
$document = $response['body']['documents'][0];
|
||||
// Verify correct Collections API attributes are present
|
||||
$this->assertArrayHasKey('$collectionId', $document, 'Collections API should set $collectionId, not $tableId');
|
||||
$this->assertArrayHasKey('$databaseId', $document);
|
||||
$this->assertArrayNotHasKey('$tableId', $document, 'Collections API should not have $tableId');
|
||||
|
||||
// Test that when $collectionId is explicitly requested in select, it's present
|
||||
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['personCollection'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('fullName', ['Stevie Wonder'])->toString(),
|
||||
Query::select(['fullName', '$collectionId', '$databaseId'])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(1, $response['body']['documents']);
|
||||
|
||||
$document = $response['body']['documents'][0];
|
||||
$this->assertArrayHasKey('$collectionId', $document, 'Explicitly requested $collectionId should be present');
|
||||
$this->assertArrayHasKey('$databaseId', $document, 'Explicitly requested $databaseId should be present');
|
||||
$this->assertArrayHasKey('fullName', $document);
|
||||
$this->assertArrayNotHasKey('$tableId', $document, 'Collections API should never have $tableId');
|
||||
|
||||
// Verify the correct value is set
|
||||
$this->assertEquals($data['personCollection'], $document['$collectionId'], '$collectionId should contain the collection ID');
|
||||
$this->assertEquals($data['databaseId'], $document['$databaseId'], '$databaseId should contain the database ID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws \Utopia\Database\Exception\Query
|
||||
|
||||
@@ -5233,6 +5233,55 @@ trait DatabasesBase
|
||||
$this->assertArrayNotHasKey('libraries', $response['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOneToManyRelationship
|
||||
*/
|
||||
public function testTableIdAttributeConsistency(array $data): void
|
||||
{
|
||||
// Test that when NO select query is used, $tableId is present (not $collectionId)
|
||||
$response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $data['databaseId'] . '/tables/' . $data['personCollection'] . '/rows', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('fullName', ['Stevie Wonder'])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(1, $response['body']['rows']);
|
||||
|
||||
$row = $response['body']['rows'][0];
|
||||
// Verify correct TablesDB attributes are present
|
||||
$this->assertArrayHasKey('$tableId', $row, 'TablesDB API should set $tableId, not $collectionId');
|
||||
$this->assertArrayHasKey('$databaseId', $row);
|
||||
$this->assertArrayNotHasKey('$collectionId', $row, 'TablesDB API should not have $collectionId');
|
||||
|
||||
// Test that when $tableId is explicitly requested in select, it's present
|
||||
$response = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $data['databaseId'] . '/tables/' . $data['personCollection'] . '/rows', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('fullName', ['Stevie Wonder'])->toString(),
|
||||
Query::select(['fullName', '$tableId', '$databaseId'])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(1, $response['body']['rows']);
|
||||
|
||||
$row = $response['body']['rows'][0];
|
||||
$this->assertArrayHasKey('$tableId', $row, 'Explicitly requested $tableId should be present');
|
||||
$this->assertArrayHasKey('$databaseId', $row, 'Explicitly requested $databaseId should be present');
|
||||
$this->assertArrayHasKey('fullName', $row);
|
||||
$this->assertArrayNotHasKey('$collectionId', $row, 'TablesDB should never have $collectionId');
|
||||
|
||||
// Verify the correct value is set
|
||||
$this->assertEquals($data['personCollection'], $row['$tableId'], '$tableId should contain the table ID');
|
||||
$this->assertEquals($data['databaseId'], $row['$databaseId'], '$databaseId should contain the database ID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Utopia\Database\Exception
|
||||
* @throws \Utopia\Database\Exception\Query
|
||||
|
||||
Reference in New Issue
Block a user