Skip to content

Query scopes #1907

@bpamiri

Description

@bpamiri

Phase 1 — Modernization Target #2

Add reusable, composable query fragments defined in the model via a scope() config method.

Design

// Model config()
scope(name="active", where="status = 'active'");
scope(name="recent", order="createdAt DESC", maxRows=10);
scope(name="byRole", handler="scopeByRole");

// Usage — composable
model("User").active().recent().findAll();
model("User").byRole("admin").findAll(page=1, perPage=25);
  • Store scope definitions in variables.wheels.class.scopes
  • Use onMissingMethod to intercept scope calls and build a query spec chain
  • Modify findAll(), findOne(), findByKey() to accept and merge query spec structs
  • Return a ScopeChain proxy object from scope calls

Backwards Compatibility

All existing findAll(where="...") calls work unchanged. Scopes are purely additive.

See design_docs/MODERNIZE-WHEELS-RIM.md §4.2 for full implementation plan.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions