[英]No relational fields in response Strapi v4
I have a problem where none of the relational fields are present in the responses after fetching my data.我有一个问题,在获取我的数据后,响应中不存在任何关系字段。 When I look to the schema of one of my schemas with a relation, I see that the relational fields are present in the attributes object.
当我查看具有关系的模式之一的模式时,我发现关系字段存在于属性 object 中。 But still I only get the non-relational fields in my response.
但我仍然只在我的回复中得到非关系字段。
This is one of my schemas这是我的模式之一
{
"kind": "collectionType",
"collectionName": "activities",
"info": {
"singularName": "activity",
"pluralName": "activities",
"displayName": "activity"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"name": {
"type": "string"
},
"date": {
"type": "date"
},
"subcategory": {
"type": "relation",
"relation": "oneToOne",
"target": "api::subcategory.subcategory"
},
"members": {
"type": "relation",
"relation": "manyToMany",
"target": "api::member.member",
"inversedBy": "activities"
}
}
}
In Strapi v4
relations are not populated when fetching entries by default.在
Strapi v4
中,默认情况下在获取条目时不会填充关系。
Queries can accept a populate
parameter to explicitly define which fields to populate, with the following syntax:查询可以接受
populate
参数来显式定义要填充的字段,语法如下:
GET /api/:pluralApiId?populate=field1,field2
GET /api/books?populate=author.name,author.address
For convenience, the * wildcard can be used to populate all first-level relations:为方便起见, * 通配符可用于填充所有一级关系:
GET /api/books?populate=*
GET /api/books?populate[author]=*
Note: Only first-level relations are populated with populate=*.
注意:只有第一级关系使用
populate=*.
Use the LHS bracket syntax (ie [populate]=*
) to populate deeper:使用 LHS 括号语法(即
[populate]=*
)进行更深的填充:
GET /api/global?populate[navigation][populate]=*
Change your API url to one of the following and you should be able to see the related fields populated in the response.将您的 API url 更改为以下之一,您应该能够看到响应中填充的相关字段。
GET /api/activities?populate=subcategory,members
OR或者
GET /api/activities?populate=*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.