From 50baa9363c2470191242ee4563b952bbdd3b8d98 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 13 Nov 2021 22:22:59 +0800 Subject: [PATCH] fix: field update with migrate --- packages/plugin-collections/src/actions/fields.ts | 8 ++++++++ packages/plugin-collections/src/server.ts | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/plugin-collections/src/actions/fields.ts b/packages/plugin-collections/src/actions/fields.ts index 8fa2e6181..5e918b665 100644 --- a/packages/plugin-collections/src/actions/fields.ts +++ b/packages/plugin-collections/src/actions/fields.ts @@ -7,3 +7,11 @@ export const create = async (ctx: Context, next: Next) => { await ctx.body.migrate(); await next(); } + +export const update = async (ctx: Context, next: Next) => { + await actions.update(ctx, async () => {}); + const { associated } = ctx.action.params; + await ctx.body.generateReverseField(); + await ctx.body.migrate(); + await next(); +} \ No newline at end of file diff --git a/packages/plugin-collections/src/server.ts b/packages/plugin-collections/src/server.ts index 80745a50c..40b2f6af8 100644 --- a/packages/plugin-collections/src/server.ts +++ b/packages/plugin-collections/src/server.ts @@ -3,7 +3,7 @@ import { Plugin } from '@nocobase/server'; import { registerModels, Table, uid } from '@nocobase/database'; import * as models from './models'; import { createOrUpdate, findAll } from './actions'; -import { create } from './actions/fields'; +import { create, update } from './actions/fields'; registerModels(models); @@ -126,9 +126,11 @@ export default { }); this.app.resourcer.registerActionHandler('collections.fields:create', create); + this.app.resourcer.registerActionHandler('collections.fields:update', update); this.app.resourcer.registerActionHandler('collections:findAll', findAll); this.app.resourcer.registerActionHandler('collections:createOrUpdate', createOrUpdate); this.app.resourcer.registerActionHandler('fields:create', create); + this.app.resourcer.registerActionHandler('fields:update', update); this.app.resourcer.registerActionHandler('collections:create', createOrUpdate); }, };