strapi 中的自定义连接点 table

Custom junction table in strapi

我最近开始研究 strapi,并在他们的文档中查看模型内部的关系。我的场景如下。我有一个名为 course 的模型和另一个命名标签。当我将它们之间的关系命名为 tag2.

 {
  "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 的结点 table。

这是标签模型的样子

  {
    "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) Is there a way I can set up the junction table as courses_tags ? i.e overriding the strapi one

2) I have set my mainField as "ui_label" in tag.settings.json but in the admin panel while editing course table content(rows in course table), in the related field of tag2 I see "code" field shown there instead of "ui_label". How to set the mainField?

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

因此,为了回答您的第一个问题,目前无法覆盖两个模型之间的联接 table。这完全由 Strapi 自动生成。

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

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

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

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