HasMany
繼承
一對多關聯
在以下的 API 參考中,將關聯的名稱加入方法中,例如 User.hasMany(Project)
,則 getter 會是 user.getProjects()
。如果關聯有別名,則改用別名,例如 User.hasMany(Project, { as: 'jobs' })
,則會是 user.getJobs()
。
方法摘要
公用方法 | ||
public |
async add(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise 將一個或多個目標列與 |
|
public |
計算目前與此關聯的所有項目,可使用可選的 where 子句。 |
|
public |
建立相關模型的新實例,並將其與此關聯。 |
|
public |
使用可選的 where 子句,取得目前與此關聯的所有項目。 |
|
public |
async has(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise 檢查一個或多個列是否與 |
|
public |
async remove(sourceInstance: Model, targetInstances: Model | Model[] | string | string[] | number | number[], options: object): Promise 取消關聯一個或多個目標列。 |
|
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 來源
將一個或多個目標列與 this
關聯。此方法接受 Model / 字串 / 數字來關聯單列,或接受 Model / 字串 / 數字的混合陣列來關聯多列。
public async count(instance: Model, options: object): Promise<number> 來源
計算目前與此關聯的所有項目,可使用可選的 where 子句。
public async create(sourceInstance: Model, values: object, options: object): Promise 來源
建立相關模型的新實例,並將其與此關聯。
public async get(instances: Model | Array<Model>, options: object): Promise<Array<Model>> 來源
使用可選的 where 子句,取得目前與此關聯的所有項目。
請參閱
- 關於選項的完整說明,請參閱 Model.findAll
public async has(sourceInstance: Model, targetInstances: Model | Model[] | string[] | string | number[] | number, options: object): Promise source
檢查一個或多個列是否與 this
關聯。
public async remove(sourceInstance: Model, targetInstances: Model | Model[] | string | string[] | number | number[], options: object): Promise source
取消關聯一個或多個目標列。