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
Recommended Reading Order
- Defining Models: shape entities and table mapping.
- Attributes + Casting: field behavior and serialization.
- Relationships: connect models with associations.
- Timestamps + Soft Deletes: lifecycle conventions.
- Scopes + Model Methods: reusable query and domain behavior.
- 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
- Define model shape + table mapping.
- Add attributes/casts.
- Add required relationships.
- Run codegen and use generated DTOs in writes.
- Add scopes/events only after query/write paths are stable.