Skip to content

EagerLoadingFieldInterface ​

Type
Interface
Namespace
craft\base
Implemented by
craft\fields\Addresses, craft\fields\Assets, craft\fields\BaseRelationField, craft\fields\Categories, craft\fields\Entries, craft\fields\Matrix, craft\fields\Tags, craft\fields\Users
Since
3.0.0

EagerLoadingFieldInterface defines the common interface to be implemented by field classes that support eager-loading.

View source

Public Methods ​

MethodDescription
getEagerLoadingGqlConditions()Returns an array that lists the scopes this custom field allows when eager-loading or null if eager-loading should not be allowed in the GraphQL context.
getEagerLoadingMap()Returns an array that maps source-to-target element IDs based on this custom field.

getEagerLoadingGqlConditions() ​

Since
3.3.0

Returns an array that lists the scopes this custom field allows when eager-loading or null if eager-loading should not be allowed in the GraphQL context.

View source

Returns ​

array, null

getEagerLoadingMap() ​

Returns an array that maps source-to-target element IDs based on this custom field.

This method aids in the eager-loading of elements when performing an element query. The returned array should contain the following keys:

  • map – an array defining source-target element mappings
  • elementType (optional) – the fully qualified class name of the element type that should be eager-loaded, if each target element is of the same element type
  • criteria (optional) – any criteria parameters that should be applied to the element query when fetching the eager-loaded elements
  • createElement (optional) - an element factory function, which will be passed the element query, the current query result data, and the first source element that the result was eager-loaded for

Each mapping listed in map should be an array with the following keys:

  • source – the source element ID
  • target – the target element ID
  • elementType (optional) – the target element type (only checked for if the top-level array doesn’t specify an elementType key)

Alternatively, the method can return an array of multiple sets of mappings, each with their own nested map, elementType, criteria, and createElement keys.

See also craft\base\ElementInterface::eagerLoadingMap()View source

Arguments ​

Returns ​

\craft\base\EagerLoadingMap, \craft\base\EagerLoadingMap[], null, false – The eager-loading element ID mappings, false if no mappings exist, or null if the result should be ignored.