Children and parents
An include: section adds related records to the result, each under a
field of the result type. This board shows a project with its owner and
its open todos:
// domains/planning/queries/project_board.jadpoquery project_board(project_id: Project.id) fails BoardNotFound -> ProjectBoardView { from: Project where: Project.id == project_id missing: BoardNotFound include: { owner: Project.owner_id todos: { via: Todo.project_id where: Todo.status == TodoStatus.open order: [Todo.created_at asc] limit: 50 } }}type ProjectBoardView = Output { pick: [Project.id, Project.name] owner: UserView todos: List<TodoView>}
Naming one of this entity's own references (Project.owner_id) includes
the record it points to, its parent. Naming another entity's reference to
this one (Todo.project_id) includes the records that point here, its
children. Children are a list, which needs order: and limit: in a
block, or at most one record when that reference is unique. A parent never
declares its children (Children).
Each include costs one more database query, however many records the
result holds, never one per record. A parent or a unique child is read by
= ANY of the keys the records hold. A list is read through a LATERAL
subquery that orders and limits each record's list on its own.
Includes nest up to two levels and stay inside the domain. They reach
another store only to fetch records by id. A parent
is included even when its lifecycle hides it, because the reference still
holds.
Markdown for agents: /docs/children-and-parents.md.Built from Jadpo main at a707efb.