$filters =
array_merge( $criteria->
getFilters(),
$criteria->
getPostFilters() );
/** @var CriteriaPartInterface $filter */
foreach ($filters as $filter) { $accessors =
$filter->
getFields();
foreach ($accessors as $accessor) { // get all fields of accessor to check which fields will be joined
$definitionFields = EntityDefinitionQueryHelper::
getFieldsOfAccessor($definition,
$accessor);
// if the criteria contains an access to a OneToMany or ManyToMany field, the query would run into a temporary table.
// to prevent overload for sql servers we will execute a minimal query with the ids at first
foreach ($definitionFields as $field) { if ($field instanceof ManyToManyAssociationField ||
$field instanceof OneToManyAssociationField
) { return true;
} } } }