Symfony 3: can't overwrite repository

Mr. B.

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!

Jakub Matczak

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't run cloned repository

From Dev

Symfony2/Doctrine can't find mapping file for custom Repository class

From Dev

Can't clone repository with Rugged

From Dev

momentJS default locale is zh-tw and can't seem to overwrite it

From Dev

Why can't I overwrite the value of a variable like this?

From Dev

Symfony: can't enable custom repository

From Dev

Can't accomplish build with Jenkins, Symfony3 and PHPUnit 5.3

From Dev

Git clone and overwrite local repository

From Dev

I can't install this repository

From Dev

Can't overwrite file on Windows

From Dev

hgsubversion can't find repository

From Dev

How to overwrite updated repository

From Dev

Can't overwrite swap

From Dev

why I can't "overwrite" a method in javascript?

From Dev

Can't Clone Git Repository

From Dev

Can't overwrite a file wrapped in a using statement

From Dev

Can't install DoctrineMigrationsBundle with Symfony3 using composer

From Dev

Can't get Symfony 3 Console to work - Autoloading Problems

From Dev

Can't accomplish build with Jenkins, Symfony3 and PHPUnit 5.3

From Dev

Can't Overwrite Text File - PHP

From Dev

Can't remove repository

From Dev

Can't send data to the Controller with a POST method Symfony3

From Dev

Symfony 3 HTTP Cache and Cross Origin Headers overwrite

From Dev

Symfony 3 error: Variable "repository" does not exist

From Dev

Can't add Docky repository

From Dev

I can't display embedded, nested form in Symfony 3

From Dev

Can't install a github repository

From Dev

Symfony 3 overwrite FOS UserTemplate - but put the Views in my Bundle

From Dev

Symfony can't access entity repository from Listener

Related Related

HotTag

Archive