Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all relationship data in one request with Directus 8 JS SDK

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?

like image 874
roNn23 Avatar asked Oct 17 '25 14:10

roNn23


1 Answers

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.

like image 131
roNn23 Avatar answered Oct 22 '25 05:10

roNn23