Skip to content

Querying tenant models with the Concurrency facade #574

Open
@IronSinew

Description

@IronSinew

Relevant context: https://laravel.com/docs/11.x/concurrency

When I attempted to use Concurrency::run() it failed as the threads did not have the context of the current tenant anymore. Is there a way to ensure that tenancy context is provided to the concurrency facade? Has anyone had any luck doing that? This is not a single schema design, or I presume that it might still return a result (even if it does not properly scope it to just the tenant).

For example:

        // presumed that the Tenant has already been made current in scope
        [$countUsers, $countPatients] = \Concurrency::run([
            User::count(),
            Patient::count(),
        ]);

        dd($countUsers, $countPatients);

Provided you have two models that have the traits UsesTenantConnection This code above fails to query as my tenant connection has no database by default, so, that empty database does not exist.

The queries work just fine outside of the concurrency facade in this example.

Edit: Clarifying that this is a multi-schema design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions