HasMany
Extends
一対多の関連付け
下記APIリファレンスでは、関連付けの名前をメソッドに追加してください。 例えば、`User.hasMany(Project)` の場合、ゲッターは `user.getProjects()` となります。 関連付けにエイリアスが付けられている場合は、エイリアスを使用してください。 例えば、`User.hasMany(Project, { as: 'jobs' })` は `user.getJobs()` となります。
メソッド概要
公開メソッド | ||
public |
async add(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise 1つ以上のターゲット行を`this`に関連付けます。 |
|
public |
オプションのwhere句を使用して、現在関連付けられているすべての行数をカウントします。 |
|
public |
関連付けられたモデルの新しいインスタンスを作成し、`this`に関連付けます。 |
|
public |
オプションのwhere句を使用して、現在関連付けられているすべての行を取得します。 |
|
public |
async has(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise 1つ以上の行が`this`に関連付けられているかどうかを確認します。 |
|
public |
async remove(sourceInstance: Model, targetInstances: Model | Model[] | string | string[] | number | number[], options: object): Promise 1つ以上のターゲット行との関連付けを解除します。 |
|
public |
async set(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise 永続化されたインスタンスまたは主キーの配列を渡すことで、関連付けられたモデルを設定します。 |
継承の概要
クラス Association から | ||
public |
関連付けの種類。 |
|
public |
|
|
public |
|
公開メソッド
public async add(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise source
1つ以上のターゲット行を`this`に関連付けます。このメソッドは、単一行を関連付けるModel/文字列/数値、または複数行を関連付けるModel/文字列/数値の混合配列を受け入れます。
public async count(instance: Model, options: object): Promise<number> source
オプションのwhere句を使用して、現在関連付けられているすべての行数をカウントします。
public async create(sourceInstance: Model, values: object, options: object): Promise source
関連付けられたモデルの新しいインスタンスを作成し、`this`に関連付けます。
public 非同期 get(instances: Model | Array<Model>, options: object): Promise<Array<Model>> ソース
オプションのwhere句を使用して、現在関連付けられているすべての行を取得します。
参照
- オプションの詳細については、Model.findAllを参照してください。
public 非同期 has(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise ソース
1つ以上の行が`this`に関連付けられているかどうかを確認します。
public 非同期 remove(sourceInstance: Model, targetInstances: Model | Model[] | string | string[] | number | number[], options: object): Promise ソース
1つ以上のターゲット行との関連付けを解除します。
public 非同期 set(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise ソース
永続化されたインスタンスまたはそれらの主キーの配列を渡すことで、関連付けられたモデルを設定します。渡された配列にないものはすべて関連付け解除されます。
パラメータ
名前 | 型 | 属性 | 説明 |
sourceInstance | Model | 新しいインスタンスを関連付けるソースインスタンス。 |
|
targetInstances | Model | Model[] | string[] | string | number[] | number |
|
このインスタンスと関連付ける、永続化されたインスタンスまたはインスタンスの主キーの配列。すべての関連付けを削除するには、`null`または`undefined`を渡します。 |
options | object |
|
|
options.validate | object |
|
結合モデルの検証を実行します。 |