Core concepts

Read this page in the documentation

Core concepts These ten pages are the working vocabulary of the ORM. Once you have read them you can model a real schema, query it, keep it valid, and change it safely — which is most of what day-to-day work needs. They assume you have been through Getting started, and they build on each other in the order below. Reading them out of order mostly works, but each one leans on the ones above it for its examples. What you already know Getting started covered connecting, defining a model, creating a table, and basic reads and writes. Everything here goes deeper into one of those, or adds something they left out. The path | Page | What it covers | Why it matters | --- | --- | --- | --- | 1 | Models | Everything a definition can express: column options, table options, naming, indexes, paranoid mode. | The shape of your model decides the shape of every query against it. | 2 | Data types | Each type, what it becomes per engine, and how values convert on the way in and out. | Picking the wrong type is expensive to undo once there is data in the column. | 3 | Querying | The finders, and how one FindOptions object compiles into SQL. | Every read goes through here, so understanding it once explains all of them. | 4 | Query operators | Comparison, range, set, pattern, null and JSON operators. | A bare value means equality; everything else needs an operator, and this is the list. | 5 | Associations | hasOne, hasMany, belongsTo, belongsToMany, and which side owns the foreign key. | Getting the owning side wrong writes the wrong table. | 6 | Eager loading | include, nesting, filtering through a join, and the required flag. | The difference between one query and N+1 of them. | 7 | Validation | Built-in validators, custom ones, and model-level rules that span fields. | Rejecting bad data before the database has to. | 8 | Hooks | The lifecycle callbacks and the order they fire in. | Where cross-cutting logic goes so it cannot be bypassed. | 9 | Transactions | Callback and unmanaged modes, isolation levels, savepoints. | Several writes that must all succeed, or none of them. | 10 | Migrations | Versioned schema change, up and down. | sync() is for development; this is for a database whose data you care about. | Two things worth reading early Associations and eager loading go together. Declaring a relationship is half the job; fetching it efficiently is the other half. If you read only two of the ten, read those. Hooks and validation overlap. Validation rejects bad values; hooks react to good ones. If you find yourself validating inside a hook, the rule probably belongs in Validation instead. After these Going further covers performance, schema tooling, the type system, and operational concerns. It is reference material — read it when a specific need comes up, not front to back. Related reading Getting started — the tutorial these follow Going further — the specialised material SQL dialects — where engines differ