$query->
from(self::
escape($table));
$useVersionFallback // only applies for versioned entities
=
$definition->
isVersionAware() // only add live fallback if the current version isn't the live version
&&
$context->
getVersionId() !== Defaults::LIVE_VERSION
// sub entities have no live fallback
&&
$definition->
getParentDefinition() === null;
if ($useVersionFallback) { $this->
joinVersion($query,
$definition,
$definition->
getEntityName(),
$context);
} elseif ($definition->
isVersionAware()) { $versionIdField =
array_filter( $definition->
getPrimaryKeys()->
getElements(),
fn ($f) =>
$f instanceof VersionField ||
$f instanceof ReferenceVersionField
);
if (!
$versionIdField) { throw new \
RuntimeException('Missing `VersionField` in `' .
$definition->
getClass() . '`'
);
} /** @var FkField $versionIdField */