1
1

【Drupal】JSON:API で Reference先のフィールド値を取得する方法

Posted at

1度のリクエストで、参照先のデータまで全部がほしいって時普通にありますよね?

例えば、記事に紐づくタグ名や、記事の投稿者のユーザー名など...。

includes

クエリパラメータにincludeを用いると参照先のデータを取得することができます。

/api/pokemon--pokemon?include=field_ref_type

fields

includesを乱用するとデータ量が大きくなりすぎるので、必要なフィールドのみを指定しましょう。
fieldsパラメータを利用すると、データ量の増大制御できます。

/api/pokemon--pokemon?include=field_ref_type&fields[type--type]=title

※ あまりにデータが大きくなりすぎる場合は、Fetchをわけてもいいかもですね。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1