{"action":"opened","issue":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/9586","repository_url":"https://api.github.com/repos/Sylius/Sylius","labels_url":"https://api.github.com/repos/Sylius/Sylius/issues/9586/labels{/name}","comments_url":"https://api.github.com/repos/Sylius/Sylius/issues/9586/comments","events_url":"https://api.github.com/repos/Sylius/Sylius/issues/9586/events","html_url":"https://github.com/Sylius/Sylius/issues/9586","id":340655896,"node_id":"MDU6SXNzdWUzNDA2NTU4OTY=","number":9586,"title":"DefaultResourceType is not multiple entity manager safe","user":{"login":"muldos","id":849186,"node_id":"MDQ6VXNlcjg0OTE4Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/849186?v=4","gravatar_id":"","url":"https://api.github.com/users/muldos","html_url":"https://github.com/muldos","followers_url":"https://api.github.com/users/muldos/followers","following_url":"https://api.github.com/users/muldos/following{/other_user}","gists_url":"https://api.github.com/users/muldos/gists{/gist_id}","starred_url":"https://api.github.com/users/muldos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muldos/subscriptions","organizations_url":"https://api.github.com/users/muldos/orgs","repos_url":"https://api.github.com/users/muldos/repos","events_url":"https://api.github.com/users/muldos/events{/privacy}","received_events_url":"https://api.github.com/users/muldos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-12T14:12:20Z","updated_at":"2018-07-12T14:12:20Z","closed_at":null,"author_association":"NONE","body":"**Sylius version affected**: 1.2\r\nAll versions prior 1.2 are affected too\r\n**Description**  \r\nIn a project using 2 databases, if you create a new resource from the non-sylius database, you can list your entities, but not create / edit resource because DefaultResourceType will always fetch a DefaultFormBuilder with default entity manager injected (and so will fail to find mapping data for the model class). \r\n\r\n**Steps to reproduce**  \r\n1 - add another db / entity manager\r\n```yaml\r\ndoctrine:\r\n    dbal:\r\n      default_connection: default\r\n      connections:\r\n        default:\r\n          driver: '%database_driver%'\r\n          host: '%database_host%'\r\n          port: '%database_port%'\r\n          dbname: '%database_name%'\r\n          user: '%database_user%'\r\n          password: '%database_password%'\r\n          server_version: '5.5'\r\n          charset: UTF8\r\n        sigadb:\r\n          driver: '%database_driver%'\r\n          host: '%database_host%'\r\n          port: '%database_port%'\r\n          dbname: 'siga'\r\n          user: '%database_user%'\r\n          password: '%database_password%'\r\n          server_version: '5.5'\r\n          charset: UTF8\r\n    orm:\r\n        default_entity_manager: default\r\n        entity_managers:\r\n            default:\r\n                connection: default\r\n                mappings:\r\n                  AppBundle:\r\n                    type: yml\r\n                    dir: Resources/config/doctrine/sylius\r\n                    prefix: AppBundle\\Entity\\Sylius\r\n                    alias: 'AppBundle'\r\n            siga_ref:\r\n                connection: sigadb\r\n                mappings:\r\n                  AppBundleSiga:\r\n                    type: yml\r\n                    dir: \"%kernel.project_dir%/src/AppBundle/Resources/config/doctrine/siga\"\r\n                    prefix: AppBundle\\Entity\\Siga\r\n                    is_bundle: false\r\n                    alias: 'AppBundleSiga'\r\n```\r\n2 - create a basic resource in the non sylius default db, with mapping, resource grids and routing\r\nThe resource file must use the other entity_manager : \r\n\r\n```yaml\r\n        app.my_resource:\r\n            options:\r\n              object_manager: siga_ref\r\n            driver: doctrine/orm\r\n            classes:\r\n                model: AppBundle\\Entity\\Siga\\MyResource\r\n```\r\n3 - go to http://sylius-dev.local/admin/my-resource/new and watch the mapping exception\r\n\r\n\r\n**Possible Solution**  \r\nThe problem is that the formbuilder is obtained from the formbuilderRegistry by passing only the driver type (ex doctrine/orm) , hence it will always fetch a defaultFormbuilder with the default EM injected.\r\nI think the object manager props should be used here, to get a defaultformbuilder injected with the non default EM specified in the resource file.\r\n![capture_d ecran_2018-07-12_a_15_40_08](https://user-images.githubusercontent.com/849186/42638368-bc3f7f7c-85ed-11e8-924c-4795d756e097.jpg)\r\n\r\nTo fix this bug, it is also necessary to register to ServiceRegistry one instance of DefaultFormBuilder per EM, and to register it with a key using driver string and the entity_manager name.\r\n\r\nFixing this bug would be a very nice feature, as it would allow sylius back-office to manage non sylius data (in my case subscriptions data).\r\n\r\nThanks in advance for your help,\r\n\r\nBest regards.\r\n\r\nDavid "}}
{"actor":{"display_login":"muldos"}}