Update has-many-repository.md

This commit is contained in:
Pearl C 2023-01-26 22:58:32 +08:00 committed by GitHub
parent dba8bbd5c5
commit f35bdc522d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,42 +1,41 @@
# HasManyRepository
`HasManyRepository` 是用于处理 `HasMany` 关系的 `Relation Repository`
`HasManyRepository` is the `Relation Repository` for handling `HasMany` relationships.
## 类方法
## Class Method
### `find()`
查找关联对象
Find associated objects.
**签名**
**Signature**
* `async find(options?: FindOptions): Promise<M[]>`
**详细信息**
**Detailed Information**
查询参数与 [`Repository.find()`](../repository.md#find) 一致。
Query parameters are the same as [`Repository.find()`](../repository.md#find).
### `findOne()`
查找关联对象,仅返回一条记录
Find associated objects, only to return one record.
**签名**
**Signature**
* `async findOne(options?: FindOneOptions): Promise<M>`
<embed src="../shared/find-one.md"></embed>
### `count()`
返回符合查询条件的记录数
Return the number of records matching the query criteria.
**签名**
**Signature**
* `async count(options?: CountOptions)`
**类型**
**Type**
```typescript
interface CountOptions extends Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'>, Transactionable {
filter?: Filter;
@ -45,23 +44,22 @@ interface CountOptions extends Omit<SequelizeCountOptions, 'distinct' | 'where'
### `findAndCount()`
从数据库查询特定条件的数据集和结果数。
Find datasets from the database with the specified filtering conditions and return the number of results.
**签名**
**Signature**
* `async findAndCount(options?: FindAndCountOptions): Promise<[any[], number]>`
**类型**
**Type**
```typescript
type FindAndCountOptions = CommonFindOptions
```
### `create()`
创建关联对象
Create associated objects.
**签名**
**Signature**
* `async create(options?: CreateOptions): Promise<M>`
@ -69,9 +67,9 @@ type FindAndCountOptions = CommonFindOptions
### `update()`
更新符合条件的关联对象
Update associated objects that match the conditions.
**签名**
**Signature**
* `async update(options?: UpdateOptions): Promise<M>`
@ -79,9 +77,9 @@ type FindAndCountOptions = CommonFindOptions
### `destroy()`
删除符合条件的关联对象
Delete associated objects.
**签名**
**Signature**
* `async destroy(options?: TK | DestroyOptions): Promise<M>`
@ -89,44 +87,43 @@ type FindAndCountOptions = CommonFindOptions
### `add()`
添加对象关联关系
Add association relationships between objects.
**签名**
**Signature**
* `async add(options: TargetKey | TargetKey[] | AssociatedOptions)`
**类型**
**Type**
```typescript
interface AssociatedOptions extends Transactionable {
tk?: TargetKey | TargetKey[];
}
```
**详细信息**
**Detailed Information**
* `tk` - 关联对象的 targetKey 值,可以是单个值,也可以是数组。
* `tk` - The targetKey value of the associated object, either as a single value or an array.
<embed src="../shared/transaction.md"></embed>
### `remove()`
移除与给定对象之间的关联关系
Remove the association with the given object.
**Signature**
**签名**
* `async remove(options: TargetKey | TargetKey[] | AssociatedOptions)`
**详细信息**
**Detailed Information**
参数同 [`add()`](#add) 方法。
Same parameters as the [`add()`](#add) method.
### `set()`
设置当前关系的关联对象
Set the associated object of the current relationship.
**签名**
**Signature**
* `async set(options: TargetKey | TargetKey[] | AssociatedOptions)`
**详细信息**
参数同 [`add()`](#add) 方法。
**Detailed Information**
Same parameters as the [`add()`](#add) method.