简体   繁体   English

在 Strapi 中解析文件时如何导入关系数据?

[英]How can I import relational data when parsing a file in Strapi?

I'm writing a script to import bulk data entries for organizations.我正在编写一个脚本来为组织导入批量数据条目。 In Strapi, however, I have a number of relational fields for the organizations with things like “area_of_focus”, “languages”, etc. My question is, how can I import the data properly for the relational when it's in a dropdown in the strapi admin panel?然而,在 Strapi 中,我有许多用于组织的关系字段,例如“area_of_focus”、“languages”等。我的问题是,当它位于 strapi 的下拉列表中时,如何正确导入关系数据管理面板? I've included the section of the code that maps and a screenshot of the relational data for reference.我已经包括了映射的代码部分和关系数据的屏幕截图以供参考。

All the data without a relation imports fine, it's just any relational field that doesn't work.所有没有关系的数据都可以正常导入,只是任何关系字段都不起作用。 I just have a feeling it's how I'm calling them, but I'm unsure.我只是有一种感觉,我就是这样称呼他们的,但我不确定。

Relational Fields:关系领域:

在此处输入图像描述

Mapping Code:映射代码:

await Promise.all(data.map(entry => 
  strapi.query('organization').create({
    name: entry.name,
    EIN: entry.EIN,
    locations: [
      {
        streetAddress: entry.streetAddress,
        city: entry.city,
        state: entry.state,
        zipCode: entry.zipCode,
        county: entry.county,
        locationType: entry.locationType,
      }
    ],
    contact: [
      {
        firstName: entry.firstName,
        lastName: entry.lastName,
        email: entry.email,
        phone: entry.phone,
        phoneExtension: entry.phoneExtension,
      }
    ],
    description: entry.description,
    webSite: entry.webSite,
    email: entry.orgEmail,
    phone: entry.orgPhone,
    priority_area_topics: entry.priority_area_topics,
    organizationType: entry.organizationType,
    areaOfFocus: entry.organization_area_of_focus,
    localServiceArea: entry.local_service_areas,
    localServiceAreaDescription: entry.localServiceAreaDescription,
    helpDesk: entry.helpDesk,
    officeHours: entry.officeHours,
    maximumResponseTime: entry.maximumResponseTime,
    languages: entry.languages,
  })
));

The easiest way to find out what the data structure looks like that Strapi expects is the documentation plugin: https://market.strapi.io/plugins/@strapi-plugin-documentation找出 Strapi 期望的数据结构的最简单方法是文档插件: https://market.strapi.io/plugins/@strapi-plugin-documentation

After installation, the plugin uses Swagger UI to display the individual services and the structure of the JSON (including relations) that the respective service expects.安装后,该插件使用 Swagger UI 显示各个服务以及各个服务期望的 JSON(包括关系)的结构。

Regarding the relations please note that there is a bug in Strapi, see: https://github.com/strapi/strapi/issues/12238 As a workaround you need to add the find-permission to the user / role who is performing the request for the related content type (you want to check first if this is a security issue for your scenario or not - alternatively you might want to try Paratron's approach which is described in the comments).关于关系,请注意 Strapi 中存在错误,请参阅: https://github.com/strapi/strapi/issues/12238作为解决方法,您需要将查找权限添加到正在执行的用户/角色请求相关的内容类型(你想首先检查这是否是你的场景的安全问题——或者你可能想尝试评论中描述的 Paratron 的方法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM