Repository: appwrite/appwrite
File: src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php (PHP)

Code before:
            ? Exception::ATTRIBUTE_LIMIT_EXCEEDED
            : Exception::COLUMN_LIMIT_EXCEEDED;
    }

    /**
     * Get the appropriate missing payload exception.
     */
    final protected function getMissingPayloadException(): string
    {
        return $this->isCollectionsAPI()
            ? Exception::DOCUMENT_MISSING_PAYLOAD
            : Exception::ROW_MISSING_PAYLOAD;
    }

    /**
     * Get the correct collections context for Events queue.
     */
    final protected function getCollectionsEventsContext(): string
    {
        return $this->isCollectionsAPI() ? 'collection' : 'table';
    }

    /**
     * Resolves relationships in a document and attaches metadata.
     */
    final protected function resolveDocumentRelations(Document $document, Document $collection, array &$context): bool
    {
        /* @type Document $database */
        $database = $context['database'];

        /* @type Database $dbForProject */
        $dbForProject = $context['dbForProject'];

        /* remove `$collection` if needed */
        $removeCollection = $context['removeCollection'] ?? false;

        /* count operations inside loop */
        $trackOperations = array_key_exists('trackOperations', $context);

        if (!$trackOperations) {
            $context['operations'] ??= 0;
        } elseif ($document->isEmpty()) {
            return false;
        }

        $operations = &$context['operations'];
        $collectionsCache = &$context['collectionsCache'];

        $operations++;
        $collectionId = $collection->getId();


Review comment (suggestion):
Let's keep this called `processDocument`, as the relations are already resolved at this point, we just need to post-process them

Code after:
            ? Exception::ATTRIBUTE_LIMIT_EXCEEDED
            : Exception::COLUMN_LIMIT_EXCEEDED;
    }

    /**
     * Get the appropriate missing payload exception.
     */
    final protected function getMissingPayloadException(): string
    {
        return $this->isCollectionsAPI()
            ? Exception::DOCUMENT_MISSING_PAYLOAD
            : Exception::ROW_MISSING_PAYLOAD;
    }

    /**
     * Get the correct collections context for Events queue.
     */
    final protected function getCollectionsEventsContext(): string
    {
        return $this->isCollectionsAPI() ? 'collection' : 'table';
    }

    /**
     * Resolves relationships in a document and attaches metadata.
     */
    final protected function processDocument(
        /* database */
        Document $database,
        Document $collection,
        Document $document,
        Database $dbForProject,

        /* options */
        array &$collectionsCache,
        ?int &$operations = null,
    ): bool {

        if ($operations !== null && $document->isEmpty()) {
            return false;
        }

        if ($operations !== null) {
            $operations++;
        }

        $collectionId = $collection->getId();
        $document->removeAttribute('$collection');
        $document->setAttribute('$databaseId', $database->getId());
        $document->setAttribute('$collectionId', $collectionId);

        $relationships = $collectionsCache[$collectionId] ??= \array_filter(