Mr. B.
Mr. B.

Reputation: 8717

Symfony 3: can't overwrite repository

I upgraded from Symfony 2.7 to 3.0. It works almost. Only problem: I'm not able to overwrite AppBundle\Entity\MyRepository in the code below, the file is not even necessary (I renamed it for testing) and got skipped by Symfony.

app/config/services.yml

# old, 2.7 (worked):
myRepositoryService:
  class: AppBundle\Entity\MyRepository
  factory_service: doctrine.orm.entity_manager
  factory_method: getRepository
  arguments: [AppBundle\Entity\MyEntity]

# new, 3.0 (skips the MyRepository):
myRepositoryService:
  class: AppBundle\Entity\MyRepository
  factory: ['@doctrine.orm.entity_manager', 'getRepository']
  arguments: ['AppBundle\Entity\MyEntity']

AppBundle\Entity\MyRepository

class MyRepository extends EntityRepository {
    public function findAll() {
        die("MyRepository->findAll()"); // not executed
    }
}

AppBundle\Controller\MyController.php

$myItems = $this->get('myRepositoryService')->findAll(); // should die but doesn't

Did I misconfigure my services.yml so that Symfony creates a temporary repository file for the entity instead of using the file I created?

Thanks in advance!

Upvotes: 2

Views: 138

Answers (1)

Jakub Matczak
Jakub Matczak

Reputation: 15686

Following code is working for me in Symfony 3.0:

some_repository:
    class: AppBundle\Repository\SomeRepository 
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments: [AppBundle:SomeEntity]

Please note the different than yours factory service name and that there are no single quotes for factory method and entity name.

Also as I've mentions in my comment, there should be repositoryClass set in entity's mapping.

Upvotes: 2

Related Questions