メインコンテンツまでスキップ
非公開のページ
このページは非公開です。 検索対象外となり、このページのリンクに直接アクセスできるユーザーのみに公開されます。

Entity Service API

Caution

The Entity Service API is deprecated in Strapi v5. Please consider using the Document Service API instead.

Prerequisites

Entity Service API のドキュメントに進む前に、次の概要を読むことを推奨します。

Strapi のバックエンドには Query Engine API を基盤にした Entity Service API があります。Entity Service は コンポーネントダイナミックゾーン などの複雑な構造を扱う層で、データベースクエリの実行には Query Engine API を使います。

Entity Service API と Query Engine API

Strapi v4 offers several layers to interact with the backend and build your queries:

  • The Document Service API is the recommended API to interact with your application's database. The Document Service is the layer that handles Strapi's document model and the complex content structures like components and dynamic zones, which the lower-level layers are not aware of.
  • The Query Engine API interacts with the database layer at a lower level and is used under the hood to execute database queries. It gives unrestricted internal access to the database layer, but should be used only if the Document Service API does not cover your use case.
  • If you need direct access to knex functions, use strapi.db.connection.
用語の整理: サービスと Entity Service

サービス から Entity Service API を呼び出せますが、サービスと Entity Service API は直接の対応関係ではありません。Strapi バックエンドの核となる要素は バックエンドのカスタマイズ のドキュメントを参照してください。

基本的な使い方

Entity Service は strapi.entityService から利用します。

const entry = await strapi.entityService.findOne('api::article.article', 1, {
populate: { someRelation: true },
});

利用できる操作

Entity Service API でエンティティに対して次の操作ができます。