core: underscore in field name does not work with @Groups
I am using doctrine.orm.naming_strategy.underscore, in generated entities, the member variables are named in snake case.
When using @Groups to select fields, any of the fields with an underscore in their name are missing from the response.
Example: service_index
Any fields that are a single word (no underscore) do not exhibit this problem.
Also, when not using @Groups everything works just fine.
If variables are named in camel case, they appear in the response even when using @Groups and even if the column in the DB is still named in snake case.
Example: serviceIndex
v2.0.11 and v.2.1.4 tested.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 16 (4 by maintainers)
Commits related to this issue
- feature #51697 [PropertyInfo] Make isWriteable() more consistent with isReadable() when checking snake_case properties (jbtronics) This PR was squashed before being merged into the 6.4 branch. Discu... — committed to symfony/symfony by nicolas-grekas 9 months ago
- feature #51697 [PropertyInfo] Make isWriteable() more consistent with isReadable() when checking snake_case properties (jbtronics) This PR was squashed before being merged into the 6.4 branch. Discu... — committed to symfony/property-info by nicolas-grekas 9 months ago
Using camel case in variables only is mandatory to develop Symfony bundles or help in the Symfony project. If your project follow PSR-12 (PSR-2 is deprecated) you can choose what do you want for variable names. I always choose snake case and have use a lot of different bundles without problems since Symfony 2, and reflection works fine in all cases. I don’t know how this issue can be closed saying “if the behavior differs from the one expected by the property info” because is a completely correct way to define a entity in Symfony and Doctrine. I hope that you can reconsider your action and try to fix it. Meanwhile, if you have this problem you can use the groups directly in the setters o getters involved. You must change from
to
closing, use custom metadata if the behavior differs from the one expected by the property info as @teohhanhui said