From a8391dfec03e6dfd412db989f61d17aba00d795a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 10 Nov 2024 11:34:43 -0500 Subject: [PATCH] docs, saveWithCtx --- server/models/Event.ts | 1 + server/models/base/Model.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/models/Event.ts b/server/models/Event.ts index 8ce6fc634b..392fa51a0a 100644 --- a/server/models/Event.ts +++ b/server/models/Event.ts @@ -55,6 +55,7 @@ class Event extends IdModel< /** * Metadata associated with the event, previously used for storing some changed attributes. + * Note that the `data` column will be visible to the client and API requests. */ @Column(DataType.JSONB) data: Record | null; diff --git a/server/models/base/Model.ts b/server/models/base/Model.ts index 5c5b5f8b41..310c4af511 100644 --- a/server/models/base/Model.ts +++ b/server/models/base/Model.ts @@ -12,6 +12,7 @@ import { InstanceUpdateOptions, ModelStatic, NonAttribute, + InstanceSaveOptions, } from "sequelize"; import { AfterCreate, @@ -29,10 +30,19 @@ class Model< TCreationAttributes extends {} = TModelAttributes > extends SequelizeModel { /** - * The namespace to use for events, if none is provided an event will not be created. + * The namespace to use for events, if none is provided an event will not be created + * during the migration period. In the future this may default to the table name. */ static eventNamespace: string | undefined; + /** + * Validates this instance, and if the validation passes, persists it to the database. + */ + public saveWithCtx(ctx: APIContext) { + this.cacheChangeset(); + return this.save(ctx.context as InstanceSaveOptions); + } + /** * This is the same as calling `set` and then calling `save`. */