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

Don't singularize TO_MANY field's variable names if target entity name is plural #5733

Closed
wants to merge 1 commit into from

Conversation

chalasr
Copy link

@chalasr chalasr commented Mar 23, 2016

According to this stackoverflow question, the Doctrine\ORM\Tools\EntityGenerator singularises the variables & methods names for add and remove setters and their parameters, for T0_MANY associations.

Example for a target entity called Dnis.

The expected result would be to have the getDnis(), addDnis(Dnis $dnis) and removeDnis(Dnis $dnis) methods generated.

But we would have getDnis(), addDni(Dnis $dni) and removeDni(Dnis $dni), that gives names that are not corresponding with the real target entity name.

I just added a small check that avoids calling Inflector::singularize($variableName|$methodName) for add+remove if the target entity name ends by s.
I also updated the test with the example I given.

I don't see any side effects for now, let me know if this breaks something, or if I can make improvements.
Thank's

@LuisMejiaF
Copy link

+1
Thanks for working on this @chalasr.

@chalasr chalasr changed the title Don't singualize TO_MANY field's variable names if target entity name is plural Don't singuarize TO_MANY field's variable names if target entity name is plural Mar 28, 2016
@chalasr chalasr changed the title Don't singuarize TO_MANY field's variable names if target entity name is plural Don't singularize TO_MANY field's variable names if target entity name is plural Mar 28, 2016
@tjaari
Copy link

tjaari commented May 15, 2016

👍 For fix this recurrent issue.

@Ex3v
Copy link

Ex3v commented Jan 30, 2017

Bump, we need this!

@Ocramius
Copy link
Member

This is adding exceptions to exceptions to exceptions, and also assuming that terminal s means plural.

Just customize the entity code as you want it after codegen.

Closing as won't fix.

@Ex3v
Copy link

Ex3v commented Jan 30, 2017

@Ocramius and we get doubled getters and setters after running generate:entities again.
👍

@Ocramius
Copy link
Member

@Ex3v why would you run generate:entities again? It's a one-time run tool.

@Ex3v
Copy link

Ex3v commented Jan 30, 2017

@Ocramius if I add new fields to model's xml, I want my popo to be updated and in sync with it.

@Ocramius
Copy link
Member

@Ex3v that's not how this tool's supposed use-case. Ref: symfony/symfony-docs#5070

@chalasr
Copy link
Author

chalasr commented Jan 30, 2017

Opened this almost a year ago. Correcting generated code for such edge cases is not a big deal. Let's move forward.

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

Successfully merging this pull request may close these issues.

5 participants