You get this error because you are trying to join an already defined alias.
The solution is to test the connections of the DQL parts. In your repository method, you can do something like this:
$joinDqlParts = $queryBuilder->getDQLParts()['join']; $aliasAlreadyExists = false; foreach ($joinDqlParts as $joins) { foreach ($joins as $join) { if ($join->getAlias() === '_user') { $aliasAlreadyExists = true; break 2; } } } if ($aliasAlreadyExists === false) { $queryBuilder->innerJoin('parenttable._user', '_user') }
So, you join only if you have not joined.
source share