【问题标题】:Custom junction table in strapiStrapi 中的自定义接线表
【发布时间】:2020-02-11 06:49:50
【问题描述】:

我最近开始研究strapi,并在他们的文档中查看模型内部的关系。我的情况如下。我有一个名为 course 的模型和另一个命名的标签。它们之间有多对多的关系。当我将它们之间的关系命名为 tag2 时,这就是 ./api/course/models/course.settings.json 所具有的。

 {
  "connection": "default",
  "collectionName": "course",
  "info": {
    "name": "course"
  },
  "options": {
    "increments": true,
    "timestamps": true
  },
  "attributes": {
    "image_link": {
      "type": "string"
    },
    "created_by": {
      "columnName": "created_by_id",
      "plugin": "users-permissions",
      "model": "user"
    },
    "updated_by": {
      "columnName": "updated_by_id",
      "plugin": "users-permissions",
      "model": "user"
    },
    "title": {
      "type": "string"
    },
    "short_description": {
      "type": "text"
    },


    "slug": {
      "type": "string",
      "unique": true
    },
    "tags2": {
      "collection": "tag",
      "via": "courses",
      "dominant": true
    }
  }
}

当我使用管理面板指定关系时,strapi 本身创建了一个名为 courses_tags_2_s__tags_courses 的连接表。

这是标签模型的样子

  {
    "connection": "default",
    "collectionName": "tag",
    "info": {
      "name": "tag",
      "mainField": "ui_label"
    },
    "options": {
      "increments": true,
      "timestamps": true
    },
    "attributes": {
      "code": {
        "type": "string"
      },
      "description": {
        "type": "string"
      },
      "created_by": {
        "plugin": "users-permissions",
        "model": "user",
        "columnName": "created_by_id"
      },
      "updated_by": {
        "plugin": "users-permissions",
        "model": "user",
        "columnName": "updated_by_id"
      },
      "ui_label": {
        "type": "string"
      },
      "courses": {
        "via": "tags2",
        "collection": "course"
      }
    }
  }

我有几个问题

1) 有没有办法可以将联结表设置为 courses_tags ?即覆盖strapi one

2) 我在 tag.settings.json 中将我的 mainField 设置为“ui_label”,但在管理面板中编辑课程表内容(课程表中的行)时,在 tag2 的相关字段中,我看到显示“代码”字段那里而不是“ui_label”。 mainField如何设置?

注意:我已经用mysql服务器设置了strapi。

【问题讨论】:

    标签: node.js relationship strapi


    【解决方案1】:

    所以回答你的第一个问题,目前没有办法覆盖两个模型之间的连接表。这完全由 Strapi 自动生成。

    对于第二个问题,这部分文档已过时。 要管理显示信息,您必须使用管理面板中的内容管理器配置。

    这里有一个简短的视频 - https://www.youtube.com/watch?v=tzipS2CePRc&list=PL7Q0DQYATmvhlHxHqfKHsr-zFls2mIVTi&index=5&t=0s

    【讨论】:

      【解决方案2】:

      对于1) Is there a way I can set up the junction table as courses_tags ? i.e overriding the strapi one

      您可以指定以下选项: "collectionName": "courses_tags"

      【讨论】:

        猜你喜欢
        • 2021-03-12
        • 2018-06-04
        • 1970-01-01
        • 2021-04-05
        • 2020-07-18
        • 1970-01-01
        • 2022-12-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多