StofDoctrineExtensionsBundle icon indicating copy to clipboard operation
StofDoctrineExtensionsBundle copied to clipboard

Repository Classes uses old ParentClass

Open RootProgger opened this issue 5 years ago • 3 comments

i use this bundle for Tree-Entitys. but when i want to extend from NestedTreeRepository.php, i see that this Class extends AbstractTreeRepository and the Abstract Class from the old "EntityRepository"

RootProgger avatar Mar 17 '20 08:03 RootProgger

Thanks for your feedback And what's the point? "Doctrine\ORM\EntityRepository" isn't deprecated

antishov avatar Mar 20 '20 20:03 antishov

The newer doctrine repository classes look like:

class ObjectTypeRepository extends ServiceEntityRepository

now you can no longer simply replace the extends with NestedTreeRepository:

class ObjectTypeRepository extends NestedListItemRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ObjectType::class);
    }
}..

Because the parent constructor doesn't take a ManagerRegistry.

A simple hack is to remove the constructor, but then you can't inject the repository in a service, because it expects a proper constructor. So the solution there is to inject the EntityManager and get the repo, but obviously the real solution is to fix the constructor call.

tacman avatar Jun 13 '21 01:06 tacman

Any chance this can fixed? It's problematic to not be able have a constructor, because (1) sometimes you need to inject other services and (2) it'd be really convenient to inject the repository into other classes.

I spent a couple of hours trying to figure this out, but it was beyond my skill level. But using this class is awesome, it's terrific for storing and retrieving tree data.

Thanks.

tacman avatar Sep 21 '21 21:09 tacman