withTenant<T> function

Future<T> withTenant<T>({
  1. required int tenantId,
  2. required Future<T> action(),
})

SMO lightly supports the concept of a multi-tenant system.

You still need to do some work yourself !

Refer to the manual for details. https://sorm.noojee.dev

Runs action with all db access scoped to only those records owned by the tenant.

You need to inject your own Transaction into the scope.

Implementation

Future<T> withTenant<T>(
    {required int tenantId, required Future<T> Function() action}) async {
  if (tenantId == Entity.notSet) {
    throw IdentityNotSetException('Invalid id ($tenantId) passed. '
        "If you don't have a tenant use 'withTenantByPass'");
  }
  return (Scope('withTenant')
        ..value<int>(Tenant.tenantIdKey, tenantId)
        ..value<bool>(Tenant._bypassTenantKey, false))
      .run(() async => action());
}