首页 > 解决方案 > 内容管理器上的新帖子未触发 Strapi 服务“创建”

问题描述

我有“漫画”和“漫画章节”。两个模型之间的关系是漫画有很多漫画章节。

我想在每个新的漫画章节上更新漫画。

./api/comicchapter/services/Comicchapter.js


  async create(data, { files } = {}) {
    const entry = await strapi.query("comicchapter").create(data);
    if (files) {
      // automatically uploads the files based on the entry and the model
      await this.uploadFiles(entry, files, { model: strapi.models.comicchapter });
      return this.findOne({ id: entry.id });
    }
    // Updating comic field
    await strapi.query("comic").update({ id: entry.comic.id }, { updated: new Date().toISOString() })
    return entry;
  },


如果我使用 http post 创建一个新的漫画章节,上面的代码可以工作,但是当我使用 contentmanager 创建一个新的漫画章节时它不起作用。使用生命周期 beforeSave afterSave 没有返回/填充 Comichapter 中的漫画。所以我不能更新漫画。有什么解决方案可以让它在内容管理器上运行吗?

标签: strapi

解决方案


根据我对您正在尝试做的事情的陈述的评论,您可以尝试自定义 Content Manager 后端以满足您的需求。

您将不得不使用自定义概念https://strapi.io/documentation/3.0.0-beta.x/concepts/customization.html#plugin-extensions来自定义 Content Manager 插件。


推荐阅读