You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
933 B

import {Model} from '../Model.ts'
import {HasOneOrMany} from './HasOneOrMany.ts'
import {Collection} from '../../../../lib/src/collection/Collection.ts'
/**
* Relation class for one-to-many relations.
* @extends HasOneOrMany
*/
export class HasMany<T extends Model<T>, T2 extends Model<T2>> extends HasOneOrMany<T, T2> {
/**
* The cached value of this relation.
* @type Collection
*/
protected _value?: Collection<T2>
/**
* True if this relation has been loaded.
* @type boolean
*/
protected _loaded = false
public async get(): Promise<Collection<T2>> {
return this.fetch().collect()
}
public set_value(related: Collection<T2>) {
this._loaded = true
this._value = related.clone()
}
public get_value(): Collection<T2> | undefined {
return this._value
}
public is_loaded(): boolean {
return this._loaded
}
}