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

Closed
opened 2026-01-22 16:05:10 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/5733

State: closed
Merged: No


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

**Original Pull Request:** https://github.com/doctrine/orm/pull/5733 **State:** closed **Merged:** No --- According to [this stackoverflow question](http://stackoverflow.com/q/36143291/4363634), 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
admin added the pull-request label 2026-01-22 16:05:10 +01:00
admin closed this issue 2026-01-22 16:05:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9710