Skip to content

Conversation

@nikophil
Copy link
Contributor

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.

@weaverryan
Copy link
Member

Wow, awesome diagnosis and fix! This rocks! I added a failing test case which confirmed the bug (and your patch DOES fix it of course). Great PR - thank you Nicolas! I hope to see you back for some more PR's ;)

@weaverryan weaverryan merged commit 535c805 into symfony:master Aug 29, 2018
weaverryan added a commit that referenced this pull request 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
@nikophil
Copy link
Contributor Author

haha thanks 👍

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 this pull request may close these issues.

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

2 participants