{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony-docs/issues/9878","repository_url":"https://api.github.com/repos/symfony/symfony-docs","labels_url":"https://api.github.com/repos/symfony/symfony-docs/issues/9878/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/issues/9878/comments","events_url":"https://api.github.com/repos/symfony/symfony-docs/issues/9878/events","html_url":"https://github.com/symfony/symfony-docs/issues/9878","id":329013348,"node_id":"MDU6SXNzdWUzMjkwMTMzNDg=","number":9878,"title":"With multiple Entity Managers (EM) the Repository uses only the mapped EM for the Entity","user":{"login":"bigs21","id":16100207,"node_id":"MDQ6VXNlcjE2MTAwMjA3","avatar_url":"https://avatars3.githubusercontent.com/u/16100207?v=4","gravatar_id":"","url":"https://api.github.com/users/bigs21","html_url":"https://github.com/bigs21","followers_url":"https://api.github.com/users/bigs21/followers","following_url":"https://api.github.com/users/bigs21/following{/other_user}","gists_url":"https://api.github.com/users/bigs21/gists{/gist_id}","starred_url":"https://api.github.com/users/bigs21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigs21/subscriptions","organizations_url":"https://api.github.com/users/bigs21/orgs","repos_url":"https://api.github.com/users/bigs21/repos","events_url":"https://api.github.com/users/bigs21/events{/privacy}","received_events_url":"https://api.github.com/users/bigs21/received_events","type":"User","site_admin":false},"labels":[{"id":25525241,"node_id":"MDU6TGFiZWwyNTUyNTI0MQ==","url":"https://api.github.com/repos/symfony/symfony-docs/labels/Actionable","name":"Actionable","color":"02e10c","default":false},{"id":32958567,"node_id":"MDU6TGFiZWwzMjk1ODU2Nw==","url":"https://api.github.com/repos/symfony/symfony-docs/labels/Doctrine","name":"Doctrine","color":"DDDDDD","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/symfony/symfony-docs/milestones/10","html_url":"https://github.com/symfony/symfony-docs/milestone/10","labels_url":"https://api.github.com/repos/symfony/symfony-docs/milestones/10/labels","id":1105130,"node_id":"MDk6TWlsZXN0b25lMTEwNTEzMA==","number":10,"title":"2.8","description":"","creator":{"login":"wouterj","id":749025,"node_id":"MDQ6VXNlcjc0OTAyNQ==","avatar_url":"https://avatars2.githubusercontent.com/u/749025?v=4","gravatar_id":"","url":"https://api.github.com/users/wouterj","html_url":"https://github.com/wouterj","followers_url":"https://api.github.com/users/wouterj/followers","following_url":"https://api.github.com/users/wouterj/following{/other_user}","gists_url":"https://api.github.com/users/wouterj/gists{/gist_id}","starred_url":"https://api.github.com/users/wouterj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wouterj/subscriptions","organizations_url":"https://api.github.com/users/wouterj/orgs","repos_url":"https://api.github.com/users/wouterj/repos","events_url":"https://api.github.com/users/wouterj/events{/privacy}","received_events_url":"https://api.github.com/users/wouterj/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":192,"state":"open","created_at":"2015-05-11T15:57:59Z","updated_at":"2018-08-28T19:29:18Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2018-06-04T11:20:01Z","updated_at":"2018-08-30T12:16:23Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"In the manual page [How to Work with multiple Entity Managers and Connections](https://symfony.com/doc/current/doctrine/multiple_entity_managers.html) for Symfony 4, we can see in the end the following code snippet:\r\n\r\n        // Retrieves a repository managed by the \"customer\" em\r\n        $customers = $this->getDoctrine()\r\n            ->getRepository(Customer::class, 'customer')\r\n            ->findAll()\r\n        ;\r\n\r\nUsing the ORM configuration code indicated in the beginning of that document, where the Customer entity is mapped to the 'customer' entity manager, the `'customer'` parameter for the `getRepository()` method is ignored.\r\nAs so, this last code about repository calls should be updated.\r\n\r\nAlso, I suggest to add the code on how to use multiple entity managers for a single Entity, or to add a note that it's not possible if that's the case."},"comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/issues/comments/417298298","html_url":"https://github.com/symfony/symfony-docs/issues/9878#issuecomment-417298298","issue_url":"https://api.github.com/repos/symfony/symfony-docs/issues/9878","id":417298298,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzI5ODI5OA==","user":{"login":"delorie","id":10212742,"node_id":"MDQ6VXNlcjEwMjEyNzQy","avatar_url":"https://avatars0.githubusercontent.com/u/10212742?v=4","gravatar_id":"","url":"https://api.github.com/users/delorie","html_url":"https://github.com/delorie","followers_url":"https://api.github.com/users/delorie/followers","following_url":"https://api.github.com/users/delorie/following{/other_user}","gists_url":"https://api.github.com/users/delorie/gists{/gist_id}","starred_url":"https://api.github.com/users/delorie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delorie/subscriptions","organizations_url":"https://api.github.com/users/delorie/orgs","repos_url":"https://api.github.com/users/delorie/repos","events_url":"https://api.github.com/users/delorie/events{/privacy}","received_events_url":"https://api.github.com/users/delorie/received_events","type":"User","site_admin":false},"created_at":"2018-08-30T12:16:23Z","updated_at":"2018-08-30T12:16:23Z","author_association":"NONE","body":"Hello,\r\n\r\nA brief introduction to our system:\r\nThe mission: we want to import data from a MSSQL database into our new application.\r\n\r\nWe have a vagrantbox, in there running the new application.\r\nAnd a docker for the MSSQL database.\r\nNow we have an Import Symfony Command Script on hostsystem that connects to the MSSQL database (Docker)\r\nand to the Maria database (Vagrantbox) via SSH 3333:172.0.0.1:3306.\r\n\r\nOur Doctrine Config\r\n```\r\ndoctrine:\r\n    dbal:\r\n        default_connection: default\r\n        types:\r\n            uuid_binary_ordered_time: Ramsey\\Uuid\\Doctrine\\UuidBinaryOrderedTimeType\r\n        connections:\r\n            default:\r\n                # configure these for your database server\r\n                driver: 'pdo_mysql'\r\n                [...]\r\n                url: '%env(resolve:DATABASE_URL)%' # Port 3306\r\n                [...]\r\n            command:\r\n                driver: 'pdo_mysql'\r\n                [...]\r\n                url: '%env(resolve:COMMAND_DATABASE_URL)%' # Port 3333\r\n                [...]\r\n\r\n    orm:\r\n        auto_generate_proxy_classes: '%kernel.debug%'\r\n        [...]\r\n        default_entity_manager: default\r\n        entity_managers:\r\n            default:\r\n                connection: default\r\n                naming_strategy: doctrine.orm.naming_strategy.underscore\r\n                mappings:\r\n                    App:\r\n                        is_bundle: false\r\n                        type: annotation\r\n                        dir: '%kernel.project_dir%/src/Entity'\r\n                        prefix: 'App\\Entity'\r\n                        alias: App\r\n            command:\r\n                connection: command\r\n                naming_strategy: doctrine.orm.naming_strategy.underscore\r\n                mappings:\r\n                    App:\r\n                        is_bundle: false\r\n                        type: annotation\r\n                        dir: '%kernel.project_dir%/src/Entity'\r\n                        prefix: 'App\\Entity'\r\n                        alias: AppCommand\r\n\r\n```\r\n\r\nIn our Command Script:\r\n```\r\n$doctrine = $this->container->get('doctrine');\r\n$doctrine->getRepository(Salutation::class, 'command')->findAll()\r\n```\r\n// But Doctrine use the default EntityManager\r\n\r\nWe found in this File:\r\nvendor/doctrine/persistence/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php\r\nDoctrine\\Common\\Persistence\\AbstractManagerRegistry\r\n\r\nThe method \"getManagerForClass\" ignores the defindet connection\r\n`getManagerForClass() (Line: 156)`\r\n[...]\r\n```\r\n\r\nforeach ($this->managers as $id) {\r\n    $manager = $this->getService($id);\r\n\r\n    if (! $manager->getMetadataFactory()->isTransient($class)) { // <-- first goal \r\n        return $manager;\r\n    }\r\n}\r\n\r\n```\r\n[...]\r\n\r\n// Debug output\r\n$this = {Doctrine\\Bundle\\DoctrineBundle\\Registry} [7]\r\n...\r\n *Doctrine\\Common\\Persistence\\AbstractManagerRegistry*managers = {array} [2]\r\n  default = \"doctrine.orm.default_entity_manager\" // <-- first goal \r\n  command = \"doctrine.orm.command_entity_manager\"\r\n...\r\n\r\n\r\nThe problem is just by Entitys with defined CustomRepositorys\r\n```\r\n/**\r\n * @ORM\\Table(name=\"salutations\")\r\n * @ORM\\Entity(repositoryClass=\"App\\Repository\\Person\\SalutationRepository\") // <-- Without CustomRepository it works\r\n */\r\nclass Salutation {}\r\n```\r\n\r\nWithout CustomRepository it works because the Method \"getRepository\" in Class \"ContainerRepositoryFactory\" found no a $customRepositoryName so the call \r\n\r\n`return $this->getOrCreateRepository($entityManager, $metadata); (Line 77) // this works finde`\r\n\r\nbut have the method found a CustomRepository the call\r\n` $repository = $this->container->get($customRepositoryName);`"}}
{"actor":{"display_login":"delorie"}}