Skip to main content

Mixin Scenarios

Use this page when you want to apply mixin-backed runtime behavior in real services and controllers.

SoftDeletes

Use this when deletes should be reversible. Use one schema declaration:
or:
Do not define both. Service methods:

EagerLoading

Use this when one service call should return a model plus its relations. Important runtime rule:
  • eager loading requires explicit relation methods on the model instance
  • schema relation metadata alone does not make load() or with() available
Example model pattern:

Serialize

Use this when API responses should hide internal fields or append computed fields.
Prefer toObject() in services and controllers. toJSON() returns a string.

Casts

Use this when booleans, dates, and JSON should be normalized automatically after reads.
Service code can then treat read values as normalized runtime data.

Scope

Use this when some records should be filtered globally from all() and find().
Current limitation:
  • scope behavior is in-memory post-fetch filtering
  • do not treat it as SQL query optimization

Hooks

Use this when audit logic, side effects, or invalidation should run around writes. Preferred model declaration:
Runtime rule:
  • register models with registerModels([...]) before relying on hook flows

PivotHelper

Use this when many-to-many behavior belongs in the service layer.

Cache

Use CacheManager and setupCache() at the service boundary for consumer-facing reads.
Then cache expensive reads and invalidate after writes:
  1. define schema and relations in models
  2. use mixin-backed behavior in services
  3. keep controllers thin
  4. keep cache logic out of controllers