最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get all relationship data in one request with Directus 8 JS SDK - Stack Overflow

programmeradmin2浏览0评论

I have the following collections: Movies and Actors.

I just want to call client.getItems('Movies') and get the data of all movies with the linked actors data per item also. It seems to me I can only do that, if I call another client.getItems with the specific ID of the actor:

client.getItems(
  'actors',
  {
    filters: {
      movie: {
        movie_id: 5
      }
    }
  }
)

Is there no other way?

I have the following collections: Movies and Actors.

I just want to call client.getItems('Movies') and get the data of all movies with the linked actors data per item also. It seems to me I can only do that, if I call another client.getItems with the specific ID of the actor:

client.getItems(
  'actors',
  {
    filters: {
      movie: {
        movie_id: 5
      }
    }
  }
)

Is there no other way?

Share Improve this question asked Mar 31, 2020 at 15:43 roNn23roNn23 1,6621 gold badge18 silver badges32 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

After chatting with the awesome folks of Directus (https://directus.chat/), I was able to solve my problem. You just have to use a field query: https://docs.directus.io/api/query/fields.html

For example:

client.getItems(
  'movies',
  {
    fields: ['*','actors.*.*']
  }
)

This will give you all movies with all data and all relational actors.

发布评论

评论列表(0)

  1. 暂无评论