Skip to main content

Models Overview

Models are the source of truth for your domain: fields, relationships, casts, lifecycle behavior, and helper methods.

Prerequisites

What You’ll Learn

  • How to move from plain Dart classes to production model design
  • Which model features to adopt first versus later
  • A practical reading order for the model docs

Step Outcome

By the end of this page, you should know:

  • Which model features to implement first for a new project
  • Which features to delay until core reads/writes are stable
  • What to read next for your current implementation phase
  1. Defining Models: shape entities and table mapping.
  2. Attributes + Casting: field behavior and serialization.
  3. Relationships: connect models with associations.
  4. Timestamps + Soft Deletes: lifecycle conventions.
  5. Scopes + Model Methods: reusable query and domain behavior.
  6. Events + Driver Overrides: advanced hooks and per-driver tuning.

Day-1 vs Advanced

  • Day-1: defining models, attributes/casts, relationships.
  • Once stable: scopes, methods, events.
  • Driver-specific behavior: add overrides only where needed.

Minimal Model Rollout

  1. Define model shape + table mapping.
  2. Add attributes/casts.
  3. Add required relationships.
  4. Run codegen and use generated DTOs in writes.
  5. Add scopes/events only after query/write paths are stable.

Read This Next