Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating entity inside folder eg: Attr\Values, and entity with name Attr already exists #192

Closed
TioLancaster opened this issue May 29, 2018 · 3 comments · Fixed by #245

Comments

@TioLancaster
Copy link

I'm trying to generate an entity, using:

php bin/console make:entity

When in the Class name of the entity I put the following value: Attr\Values, and the Attr class already exists, so:
\App\Entity\Attr.php
\App\Entity\Attr\Values.php ( the new one I'm creating ), the following happens:

created: src/Entity/Attr/Values.php
created: src/Repository/Attr/ValuesRepository.php
2018-05-29T15:47:54+00:00 [error] Error thrown while running command "make:entity". Message: "Call to a member function getName() on string"
2018-05-29T15:47:54+00:00 [critical] Call to a member function getName() on string

In MakeEntity.php line 837:

Call to a member function getName() on string

The curious thing, is that the entity is created, nothing is changed on the Attr entity, and if run the command again to edit the entity Attr\Values, everything is fine, and everything works perfectly.

I'm on Windows 10, and running v1.5.0 of maker-bundle.

@nikophil
Copy link
Contributor

i have the same troubles :

  • symfony 4.1.0
  • symfony/maker-bundle 1.5.0

on ubuntu

@LauLaman
Copy link

i got the same problem,
However when i run the command again for the same Entity i am able to add fields

weaverryan added a commit that referenced this issue Aug 29, 2018
weaverryan added a commit that referenced this issue Aug 29, 2018
This PR was merged into the 1.0-dev branch.

Discussion
----------

fix MakerEntity when generating entity inside folder

fixes #192

When we're trying to generate an entity inside a folder, and when the namespace of the newly created correspond to an entity that already exists, an error occurs :

> In MakeEntity.php line 840:
> Call to a member function getName() on string

Ex :
An entity called App\Entity\BlogPost exists, and we try to create an entity named "BlogPost\Comment"

Actually `Str::getNamespace($className)` refers to an existing class and not to a namespace, then $doctrineHelper->getMetadata() won't return an array, but a single metadata, and this leads to an error.

To prevent this behavior, the easier way is to put a trailing backslash at the end of the namespace name, so we know it won't refer to a classname.

Commits
-------

535c805 fix MakerEntity when generating entity inside folder
@weaverryan
Copy link
Member

Thanks for the report guys! Sorry this bug persisted for a bit - thanks to @nikophil for fixing it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants