JakubMisek I got some errors with generic:
my composer.json
{
"require": {
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14"
}
}
<?php
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class Category {}
/**
* @extends ServiceEntityRepository<Category>
*
* @method Category|null find($id, $lockMode = null, $lockVersion = null)
* @method Category|null findOneBy(array $criteria, array $orderBy = null)
* @method Category[] findAll()
* @method Category[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CategoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}
public function save(Category $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
}
/**
* @return list<Category>
*/
public function findRootCategories(): array
{
return $this->createQueryBuilder('c')
->where('c.parent is NULL')
->getQuery()
->getResult();
}
}
i got an error Call to unknown method: CategoryRepository::getEntityManager()
when have @extends ServiceEntityRepository<Category>
in docblock