symfony / maker-bundle

Symfony Maker Bundle
https://symfony.com/
MIT License
3.36k stars 406 forks source link

[Console] Bug with multiple entity_managers #921

Open inzanty opened 3 years ago

inzanty commented 3 years ago

Symfony version(s) affected: 5.3.3

Description I need to define two entity managers and my config looks similar this:

        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Web:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Web'
                        prefix: 'App\Entity\Web'
                        alias: Web
            stats:
                connection: stats
                mappings:
                    Stats:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Stats'
                        prefix: 'App\Entity\Stats'
                        alias: Stats

How to reproduce If execute php bin/console make:entity command, i will get this error:

         <info>App\Entity\User</info> class uses a different format. If you would
         like this command to generate the properties & getter/setter methods, add
         your mapping configuration, and then re-run this command with the
         <info>--regenerate</info> flag.

Possible Solution Exactly don't know how to fix this problem.

Additional context Screenshot_11

inzanty commented 3 years ago

I managed to create an entity by giving it a full name, example: php bin/console make:entity Web\Test. It's better to clarify this in the documentation here. Other variant, mention this when user create an entity via console.

SimonMarx commented 3 years ago

To create entities the maker bundle needs the mapping information which are provided by doctrine. When you are using 2 Entity Managers and have two mappings leading to App\Entity\Web and App\Entity\Stats, doctrine do not have any mapping for App\Entity (could be that some default mapping exists but without type: annotation, idk).

In case you are not using the FQCN, the maker-bundle should not use automatically which of your both mapping should be used to create the User entity.

I think a better error message would be something like Creation of entity for the namespace "App\Entity\" failed. No doctrine mapping found for that namespace. Configured namespaces are "App\Entity\Web", "App\Entity\Stats", "...". Create a new mapping for namespace "App\Entity\" or enter the FQCN of the entity you want to create/update.

Or we could provide a choice input in case we found multiple entity managers, where the user can select a namespace to create the entity for, in case no FQCN is provided in his input :)?