Skip to content

Commit

Permalink
EM: getRepository: ClassName must be a entity, never repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Nov 16, 2021
1 parent ed47d83 commit d6330cd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,18 @@ public function refresh($object): void


/**
* @param string $className
* @param class-string $className
*/
public function getRepository($className): EntityRepository
{
$metadata = parent::getClassMetadata($className);
try {
$metadata = parent::getClassMetadata($className);
} catch (\Doctrine\ORM\Mapping\MappingException $e) {
if (is_subclass_of($className, EntityRepository::class)) {
throw new \InvalidArgumentException(sprintf('Get repository for "%s" is not allowed, please use entity name.', $className), 500, $e);
}
throw $e;
}
$repository = $metadata->customRepositoryClassName ?? Repository::class;

return new $repository($this, $metadata);
Expand Down

0 comments on commit d6330cd

Please sign in to comment.