javascript - 在 Strapi 中的关系之间,我如何检索名称/标题而不是 id
问题描述
Strapi 版本:3.6.8
操作系统:big sur 11.6
数据库:postgresql
节点版本:14.17.5
NPM 版本:8.0.0
纱线版本:1.22.11
我有一个帖子集合类型,与以下集合类型具有多对多关系:-tags -categories 和一对多关系:-users(来自:users-permissions)
假设我想为用户和标签创建页面,它们都显示各自的帖子。问题是,类别仅显示为 id 而不是它们的指定名称。有什么办法可以解决这种情况?
附加信息:
类别.settings.json:
{
"kind": "collectionType",
"collectionName": "categories",
"info": {
"name": "Categories"
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": false
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"Name": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string",
"unique": true,
"required": true
},
"slug": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string",
"required": true,
"unique": true
},
"posts": {
"via": "categories",
"collection": "post"
}
}
}
post.settings.json:
{
"kind": "collectionType",
"collectionName": "posts",
"info": {
"name": "Post",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"title": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string"
},
"thumbnail": {
"model": "file",
"via": "related",
"allowedTypes": [
"images"
],
"plugin": "upload",
"required": false,
"pluginOptions": {
"i18n": {
"localized": false
}
}
},
"wide_thumbnail": {
"model": "file",
"via": "related",
"allowedTypes": [
"images"
],
"plugin": "upload",
"required": false,
"pluginOptions": {
"i18n": {
"localized": true
}
}
},
"user": {
"via": "posts",
"plugin": "users-permissions",
"model": "user"
},
"slug": {
"pluginOptions": {},
"type": "uid",
"targetField": "title"
},
"publication_date": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "date"
},
"tags": {
"targetColumnName": "",
"via": "posts",
"collection": "tag",
"dominant": true
},
"comments": {
"plugin": "comments",
"collection": "comment"
},
"youtube": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string"
},
"season": {
"model": "season",
"via": "posts"
},
"isFeature": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "boolean"
},
"content": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "richtext",
"required": true
},
"spotify": {
"pluginOptions": {
"i18n": {
"localized": false
}
},
"type": "string"
},
"description": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string"
},
"categories": {
"via": "posts",
"collection": "categories"
}
}
}
标签.settings.json:
{
"kind": "collectionType",
"collectionName": "tags",
"info": {
"name": "tag",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": false
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"name": {
"pluginOptions": {
"i18n": {
"localized": false
}
},
"type": "string"
},
"posts": {
"via": "tags",
"collection": "post"
},
"slug": {
"type": "uid",
"targetField": "name"
}
}
}
感谢您的时间。
解决方案
推荐阅读
- google-apps-script - Gmail Addon 与外部站点之间的通信
- python - 在字典中创建字典
- icalendar - .ics 文件是否有“正确”的文件名?
- reactjs - 在 React 中使用 Jest 进行测试时如何调用 ComponentDidMount
- mysql - mysql查询magento连续左连接问题
- vue.js - 表单 $ref 在方法内部未定义?
- python - 将 int 转换为 IEEE float 的 Python 结构
- jdbc - 如何为 hive JDBC 创建连接池
- android - 为什么可以使用在后台线程中创建的 Handler 来更新 UI?
- java - 开放API。Generic 的无效请求示例