From 5a3acf30f439be6d4c71089c104405237260189e Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Wed, 2 Sep 2020 14:08:49 +0200 Subject: [PATCH] OneModelRelation: add set(), clear() methods --- src/db/ModelRelation.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/db/ModelRelation.ts b/src/db/ModelRelation.ts index baa9a0e..1704ecb 100644 --- a/src/db/ModelRelation.ts +++ b/src/db/ModelRelation.ts @@ -113,6 +113,13 @@ export class OneModelRelation extends ModelRel this.cachedModels = models.filter(m => m[this.dbProperties.foreignKey] === this.getModelID())[0] || null; } + public async set(model: O): Promise { + (this.model as Model)[this.dbProperties.localKey] = model[this.dbProperties.foreignKey]; + } + + public async clear(): Promise { + (this.model as Model)[this.dbProperties.localKey] = undefined; + } } export class ManyModelRelation extends ModelRelation {