Thomas Landauer
Thomas Landauer

Reputation: 8355

Error: Argument 1 passed to App\Repository\FooRepository::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry

After updating to doctrine/doctrine-bundle 2.1.2 I'm getting this error:

Argument 1 passed to App\Repository\FooRepository::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in ...

My Repository looks like this:

namespace App\Repository;

use App\Entity\Foo;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

class FooRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Foo::class);
    }
}

=> See my own answer below.

Upvotes: 17

Views: 15247

Answers (1)

Thomas Landauer
Thomas Landauer

Reputation: 8355

Just change this use line from

use Doctrine\Common\Persistence\ManagerRegistry;

to

use Doctrine\Persistence\ManagerRegistry;

Documentation: https://symfony.com/doc/current/doctrine.html#querying-for-objects-the-repository

Upvotes: 55

Related Questions