havingAccompanyingPeriodInJoin($query)) { if (false === in_array('person', $query->getAllAliases(), true)) { throw new LogicException("the alias 'person' does not exists in " . 'query builder'); } $query->join('person.accompanyingPeriods', 'accompanying_period'); } } /** * Return true if "accompanying_period" alias is present in the query alises. */ protected function havingAccompanyingPeriodInJoin(QueryBuilder $query): bool { $joins = $query->getDQLPart('join') ?? []; return in_array('accompanying_period', $query->getAllAliases(), true); } }