Documentation Index
Fetch the complete documentation index at: https://www.esixorm.com/llms.txt
Use this file to discover all available pages before exploring further.
Relationships
Models in your application are rarely isolated. Esix ships with three ActiveRecord-style helpers that make it easy to traverse relationships between collections:hasMany, hasOne, and belongsTo.
Each helper follows the same convention: by default, the foreign key is the
camelCased class name with Id appended (e.g. Author → authorId), and the
local/owner key is id. Both keys can be overridden when your schema differs.
hasMany
UsehasMany when a parent record can own many related records. It returns a
QueryBuilder, so you can chain additional constraints before fetching:
hasOne
hasOne mirrors hasMany but returns a single record (or null). It’s the
right choice for true one-to-one relationships such as a user and their
profile:
hasMany, you can override the foreign and local keys:
belongsTo
belongsTo is the inverse of hasOne / hasMany: it looks up the parent
record from a foreign key stored on the current model.
belongsTo uses the parent’s id as the owner key and looks up the
foreign key derived from the parent class name. Override either if your schema
uses different fields:
null or undefined on the current model, belongsTo
returns null without hitting the database.