2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
# HasManyRepository
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
`HasManyRepository` is the `Relation Repository` for handling `HasMany` relationships.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
## Class Method
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
### `find()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Find associated objects.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async find(options?: FindOptions): Promise<M[]>`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Detailed Information**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Query parameters are the same as [`Repository.find()`](../repository.md#find).
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
### `findOne()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Find associated objects, only to return one record.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async findOne(options?: FindOneOptions): Promise<M>`
|
|
|
|
|
|
|
|
<embed src="../shared/find-one.md"></embed>
|
|
|
|
|
|
|
|
### `count()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Return the number of records matching the query criteria.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async count(options?: CountOptions)`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Type**
|
2023-01-27 14:24:45 +00:00
|
|
|
|
2022-10-31 03:52:17 +00:00
|
|
|
```typescript
|
|
|
|
interface CountOptions extends Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'>, Transactionable {
|
|
|
|
filter?: Filter;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### `findAndCount()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Find datasets from the database with the specified filtering conditions and return the number of results.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async findAndCount(options?: FindAndCountOptions): Promise<[any[], number]>`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Type**
|
2023-01-27 14:24:45 +00:00
|
|
|
|
2022-10-31 03:52:17 +00:00
|
|
|
```typescript
|
|
|
|
type FindAndCountOptions = CommonFindOptions
|
|
|
|
```
|
|
|
|
|
|
|
|
### `create()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Create associated objects.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async create(options?: CreateOptions): Promise<M>`
|
|
|
|
|
|
|
|
<embed src="../shared/create-options.md"></embed>
|
|
|
|
|
|
|
|
### `update()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Update associated objects that match the conditions.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async update(options?: UpdateOptions): Promise<M>`
|
|
|
|
|
|
|
|
<embed src="../shared/update-options.md"></embed>
|
|
|
|
|
|
|
|
### `destroy()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Delete associated objects.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async destroy(options?: TK | DestroyOptions): Promise<M>`
|
|
|
|
|
|
|
|
<embed src="../shared/destroy-options.md"></embed>
|
|
|
|
|
|
|
|
### `add()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Add association relationships between objects.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2023-01-27 14:24:45 +00:00
|
|
|
|
2022-10-31 03:52:17 +00:00
|
|
|
* `async add(options: TargetKey | TargetKey[] | AssociatedOptions)`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Type**
|
2023-01-27 14:24:45 +00:00
|
|
|
|
2022-10-31 03:52:17 +00:00
|
|
|
```typescript
|
|
|
|
interface AssociatedOptions extends Transactionable {
|
|
|
|
tk?: TargetKey | TargetKey[];
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Detailed Information**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
* `tk` - The targetKey value of the associated object, either as a single value or an array.
|
2022-10-31 03:52:17 +00:00
|
|
|
<embed src="../shared/transaction.md"></embed>
|
|
|
|
|
|
|
|
### `remove()`
|
|
|
|
|
2023-01-27 14:24:45 +00:00
|
|
|
Remove the association with the given objects.
|
2023-01-26 14:58:32 +00:00
|
|
|
|
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async remove(options: TargetKey | TargetKey[] | AssociatedOptions)`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Detailed Information**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Same parameters as the [`add()`](#add) method.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
### `set()`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Set the associated object of the current relationship.
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Signature**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
|
|
|
* `async set(options: TargetKey | TargetKey[] | AssociatedOptions)`
|
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
**Detailed Information**
|
2022-10-31 03:52:17 +00:00
|
|
|
|
2023-01-26 14:58:32 +00:00
|
|
|
Same parameters as the [`add()`](#add) method.
|