From e447c5e2ae966a1e2cbb241815e67c1e2f6ef2dc Mon Sep 17 00:00:00 2001 From: Pearl C <63629092+pearl-cao@users.noreply.github.com> Date: Thu, 26 Jan 2023 22:47:12 +0800 Subject: [PATCH] Update has-one-repository.md --- .../relation-repository/has-one-repository.md | 77 +++++++++---------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/docs/en-US/api/database/relation-repository/has-one-repository.md b/docs/en-US/api/database/relation-repository/has-one-repository.md index 66ea4a65e..3925b6c43 100644 --- a/docs/en-US/api/database/relation-repository/has-one-repository.md +++ b/docs/en-US/api/database/relation-repository/has-one-repository.md @@ -1,7 +1,8 @@ # HasOneRepository -## 概览 -`HasOneRepository` 为 `HasOne` 类型的关联 Repository。 +## Overview + +`HasOneRepository` is the associated repository of type `HasOne`. ```typescript const User = db.collection({ @@ -21,28 +22,24 @@ const user = await User.repository.create({ values: { name: 'u1' }, }); - -// 获取到关联 Repository +// Get the associated repository const userProfileRepository = User.repository.relation('profile').of(user.get('id')); -// 也可直接初始化 +// Or to initialize directly new HasOneRepository(User, 'profile', user.get('id')); - - - ``` -## 类方法 +## Class Method ### `find()` -查找关联对象 +Find associated object. -**签名** +**Signature** * `async find(options?: SingleRelationFindOption): Promise | null>` -**类型** +**Type** ```typescript interface SingleRelationFindOption extends Transactionable { @@ -53,27 +50,28 @@ interface SingleRelationFindOption extends Transactionable { } ``` -**详细信息** +**Detailed Information** -查询参数与 [`Repository.find()`](../repository.md#find) 一致。 +Query parameters are the same as [`Repository.find()`](../repository.md#find). -**示例** +**Example** ```typescript const profile = await UserProfileRepository.find(); -// 关联对象不存在时,返回 null +// Return null if the associated object does not exist ``` ### `create()` -创建关联对象 -**签名** +Create associated object. + +**Signature** * `async create(options?: CreateOptions): Promise` -**示例** +**Example** ```typescript const profile = await UserProfileRepository.create({ @@ -95,16 +93,15 @@ console.log(profile.toJSON()); ### `update()` -更新关联对象 +Update associated object. -**签名** +**Signature** * `async update(options: UpdateOptions): Promise` - -**示例** +**Example** ```typescript const profile = await UserProfileRepository.update({ @@ -116,17 +113,17 @@ profile.get('avatar'); // 'avatar2' ### `remove()` -移除关联对象,仅解除关联关系,不删除关联对象 +Remove associated object. Only to unassociate, not to delete the associated object. -**签名** +**Signature** * `async remove(options?: Transactionable): Promise` -**详细信息** +**Detailed Information** -* `transaction`: 事务对象。如果没有传入事务参数,该方法会自动创建一个内部事务。 +* `transaction`: Transaction object. If no transaction parameter is passed, the method will automatically create an internal transaction. -**示例** +**Example** ```typescript await UserProfileRepository.remove(); @@ -137,18 +134,18 @@ await Profile.repository.count() === 1; // true ### `destroy()` -删除关联对象 +Delete associated object. -**签名** +**Signature** * `async destroy(options?: Transactionable): Promise` -**详细信息** +**Detailed Information** -* `transaction`: 事务对象。如果没有传入事务参数,该方法会自动创建一个内部事务。 +* `transaction`: Transaction object. If no transaction parameter is passed, the method will automatically create an internal transaction. -**示例** +**Example** ```typescript await UserProfileRepository.destroy(); @@ -158,25 +155,25 @@ await Profile.repository.count() === 0; // true ### `set()` -设置关联对象 +Set associated object. -**签名** +**Signature** * `async set(options: TargetKey | SetOption): Promise` -**类型** +**Type** ```typescript interface SetOption extends Transactionable { tk?: TargetKey; } ```` -**详细信息** +**Detailed Information** -* tk: 设置关联对象的 targetKey -* transaction: 事务对象。如果没有传入事务参数,该方法会自动创建一个内部事务。 +* tk: Set the targetKey of the associated object. +* transaction: Transaction object. If no transaction parameter is passed, the method will automatically create an internal transaction. -**示例** +**Example** ```typescript const newProfile = await Profile.repository.create({