Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,48 @@ const config: PaginateConfig<CatEntity> = {
const result = await paginate<CatEntity>(query, catRepo, config)
```

## Usage with to-many relationships

You can filter parents by conditions on their to-many relations (one-to-many or many-to-many) using quantifiers.
Quantifiers define how many related rows must satisfy the condition:

- `$any` (default): at least one related row matches the condition
- `$all`: all related rows match the condition
- `$none`: no related rows match the condition

### Examples
Assume `CatEntity` has a one‑to‑many relation `toys: CatToyEntity[]` where `CatToyEntity` has a string column `name`.

- At least one toy named exactly "Ball":

```url
GET /cats?filter.toys.name=$any:$eq:Ball
```

- At least one toy whose name contains "red" (case-insensitive):

```url
GET /cats?filter.toys.name=$any:$ilike:red
```

- All toys must have names that start with "Chew":

```url
GET /cats?filter.toys.name=$all:$sw:Chew
```

- No toys named "Squeaky", including cats without any toys:

```url
GET /cats?filter.toys.name=$none:$eq:Squeaky
```

- One or more toys not named "Squeaky":

```url
GET /cats?filter.toys.name=$any:$not:$eq:Squeaky
```

## Usage with Eager Loading

Eager loading should work with TypeORM's eager property out of the box:
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/cat-home-pillow.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { Column, CreateDateColumn, DeleteDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { CatHomePillowBrandEntity } from './cat-home-pillow-brand.entity'
import { CatHomeEntity } from './cat-home.entity'
import { DateColumnNotNull } from './column-option'
Expand All @@ -19,4 +19,7 @@ export class CatHomePillowEntity {

@CreateDateColumn(DateColumnNotNull)
createdAt: string

@DeleteDateColumn(DateColumnNotNull)
deletedAt: string
}
Loading
Loading