OneModelRelation: add set(), clear() methods

This commit is contained in:
Alice Gaudon 2020-09-02 14:08:49 +02:00
parent 4b9b62517b
commit 5a3acf30f4
1 changed files with 7 additions and 0 deletions

View File

@ -113,6 +113,13 @@ export class OneModelRelation<S extends Model, O extends Model> extends ModelRel
this.cachedModels = models.filter(m => m[this.dbProperties.foreignKey] === this.getModelID())[0] || null;
}
public async set(model: O): Promise<void> {
(this.model as Model)[this.dbProperties.localKey] = model[this.dbProperties.foreignKey];
}
public async clear(): Promise<void> {
(this.model as Model)[this.dbProperties.localKey] = undefined;
}
}
export class ManyModelRelation<S extends Model, O extends Model> extends ModelRelation<S, O, O[]> {