简体   繁体   English

strapi 获取关系数据

[英]Strapi get relational data

I am new to Strapi and building an application were an authicated user should be able to save bookmarks.我是 Strapi 的新手,正在构建一个应用程序,授权用户应该能够保存书签。 On the dashboard for the logged in user it should display a list of the user's bookmarks.在登录用户的仪表板上,它应该显示用户书签列表。 However, I seem to be unable to get the relations user has many bookmarks .但是,我似乎无法获得user has many bookmarks的关系。 I have tried several ways, for instance creating a custom controller with the following:我尝试了几种方法,例如使用以下内容创建自定义 controller:

const data = await strapi.services.bookmarks.find({ Users_premissions_user: { id: 1 } });

I have also tried with /users/me , but that only returns basic information about the user (no relational data).我也尝试过/users/me ,但它只返回有关用户的基本信息(没有关系数据)。 Basically, what I want to achieve is something similar to SELECT * FROM bookmarks WHERE user_id = 1 .基本上,我想要实现的是类似于SELECT * FROM bookmarks WHERE user_id = 1的东西。

Any help or pointers is appreciated.任何帮助或指示表示赞赏。

You'll need to deeply populate the response.您需要深入填充响应。 You can add a populate query to the API call您可以向 API 调用添加填充查询

http://localhost:1337/api/[collection/single type]?populate=*

or..或者..

if you're on StrapiV4 you can check out this populate deep plugin如果你使用的是 StrapiV4,你可以查看这个 populate deep插件

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

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