Repository: appwrite/appwrite
File: tests/e2e/Services/Databases/TablesDB/DatabasesBase.php (PHP)

Code before:
            'x-appwrite-project' => $this->getProject()['$id'],
            'x-appwrite-key' => $this->getProject()['apiKey']
        ]), [
            'relatedTableId' => $childTableId,
            'type' => Database::RELATION_ONE_TO_MANY,
            'twoWay' => false,
            'key' => 'children',
        ]);
        $this->assertEquals(202, $relationship['headers']['status-code']);

        // Wait for relationship column to be available
        $maxAttempts = 10;
        $childrenFound = false;
        for ($i = 0; $i < $maxAttempts; $i++) {
            $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns', array_merge([
                'content-type' => 'application/json',
                'x-appwrite-project' => $this->getProject()['$id'],
                'x-appwrite-key' => $this->getProject()['apiKey']
            ]));
            $columnKeys = array_column($columns['body']['columns'], 'key');
            if (in_array('children', $columnKeys)) {
                $childrenFound = true;
                break;
            }
            usleep(200000);
        }
        $this->assertTrue($childrenFound, "Relationship column 'children' not found in table {$parentTableId} of database {$databaseId}");

        // ID too long (>36 chars) should fail
        $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([
            'content-type' => 'application/json',
            'x-appwrite-project' => $this->getProject()['$id'],
            'x-appwrite-key' => $this->getProject()['apiKey']
        ]), [
            'rowId' => ID::unique(),
            'data' => [
                'name' => 'Parent 1',
                'children' => [
                    [
                        '$id' => 'this_id_is_way_too_long_and_should_fail_validation_check',
                        'title' => 'Child 1',
                    ],
                ],
            ],
        ]);
        $this->assertEquals(400, $response['headers']['status-code']);

        // ID with invalid characters should fail
        $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([
            'content-type' => 'application/json',
            'x-appwrite-project' => $this->getProject()['$id'],

Review comment (refactor):
We have a helper method, `assertEventually` that can handle this kind of polling internally

Code after:
            'x-appwrite-project' => $this->getProject()['$id'],
            'x-appwrite-key' => $this->getProject()['apiKey']
        ]), [
            'relatedTableId' => $childTableId,
            'type' => Database::RELATION_ONE_TO_MANY,
            'twoWay' => false,
            'key' => 'children',
        ]);
        $this->assertEquals(202, $relationship['headers']['status-code']);

        // Wait for relationship column to be available
        $this->assertEventually(function () use ($databaseId, $parentTableId) {
            $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns', array_merge([
                'content-type' => 'application/json',
                'x-appwrite-project' => $this->getProject()['$id'],
                'x-appwrite-key' => $this->getProject()['apiKey']
            ]));
            $columnKeys = array_column($columns['body']['columns'], 'key');
            $this->assertContains('children', $columnKeys, "Relationship column 'children' not found in table {$parentTableId} of database {$databaseId}");
        }, 2000, 200);

        // ID too long (>36 chars) should fail
        $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([
            'content-type' => 'application/json',
            'x-appwrite-project' => $this->getProject()['$id'],
            'x-appwrite-key' => $this->getProject()['apiKey']
        ]), [
            'rowId' => ID::unique(),
            'data' => [
                'name' => 'Parent 1',
                'children' => [
                    [
                        '$id' => 'this_id_is_way_too_long_and_should_fail_validation_check',
                        'title' => 'Child 1',
                    ],
                ],
            ],
        ]);
        $this->assertEquals(400, $response['headers']['status-code']);

        // ID with invalid characters should fail
        $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([
            'content-type' => 'application/json',
            'x-appwrite-project' => $this->getProject()['$id'],
            'x-appwrite-key' => $this->getProject()['apiKey']
        ]), [
            'rowId' => ID::unique(),
            'data' => [
                'name' => 'Parent 2',
                'children' => [
                    [