registerGlobalScope<T extends OrmEntity> method

void registerGlobalScope<T extends OrmEntity>(
  1. String identifier,
  2. GlobalScopeCallback<T> scope
)

Registers a global scope for models of type T.

Global scopes are automatically applied to all queries for a given model type.

identifier is a unique identifier for the global scope. scope is the callback function that applies the scope's constraints to a query.

Implementation

void registerGlobalScope<T extends OrmEntity>(
  String identifier,
  GlobalScopeCallback<T> scope,
) {
  scopeRegistry.addGlobalScope<T>(identifier, scope);
  // Also register for the actual model type if T is an alias
  try {
    final definition = registry.expect<T>();
    final actualType = definition.modelType;
    if (actualType != T) {
      scopeRegistry.addGlobalScopeForType(
        actualType,
        identifier,
        (query) => scope(query as Query<T>) as Query<OrmEntity>,
      );
    }
  } catch (_) {
    // If the type is not registered, just register the scope for T only
  }
}