Skip to main content
LoaderQuery is a system for efficiently loading 1:N and N:M relation data.

LoaderQuery Overview

1:N Relations

Parent → Multiple children HasMany

N:M Relations

Bidirectional many-to-many ManyToMany

N+1 Solution

Efficient data loading Batch Loading

Nested Loaders

Recursive relation loading Nested Relations

LoaderQuery vs SubsetQuery

SubsetQuery (JOIN)

Suitable for OneToOne or BelongsTo relations:

LoaderQuery (Separate Query)

Suitable for HasMany or ManyToMany relations:

Defining LoaderQuery

LoaderQuery is defined in subset-loaders.ts files:
LoaderQuery automatically performs Batch Loading to solve the N+1 problem.

1:N Relations (HasMany)

Department → Employees

Usage Example:

N:M Relations (ManyToMany)

Project ↔ Employee

Usage Example:

Nested LoaderQuery

Nested LoaderQuery structure
LoaderQuery can be nested recursively:
Result Structure:

How Batch Loading Works

N+1 problem and Batch Loading solution

N+1 Problem

Batch Loading Solution

Practical Examples

Department Employee List

Project Dashboard

User Activity Summary

LoaderQuery Design Principles

1. SELECT Only Needed Fields

2. Sorting and Limiting

3. Condition Filtering

Next Steps

Defining Subsets

Create Subsets in Entity

Using Subsets

Use Subsets in Model

Model Methods

Model CRUD methods

Puri Joins

Puri JOIN queries