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

Use field.name rather than field.nested_form.resource_name for Field::HasOne labels #2164

Merged
merged 3 commits into from
Mar 31, 2022

Conversation

edwinwills
Copy link
Contributor

If a model has multiple has_one relationships to the same model (e.g. two has_one associations with different scopes), we can't override the field label for the two associations, we can only change the translation for both at the same time, as the translation is based on the associated class name, not the association name.

This change uses the association name as the lookup field and default value for the label for has_one relationships, allowing multiple relations to the same class to have their own translated labels.

This is a potential breaking change for apps that have set a translation label based on the class name, but have a custom-named association (e.g. if a model has the association :external_user pointing to a User class, the translated label would be listed under user and would need to be changed to external_user.

If a model has multiple has_one relationships to the same model (e.g. two polymorphic associations with different scopes), we can't override the field label for the two associations, we can only change the translation for both at the same time, as the translation is based on the associated class name, not the association name.

This change uses the association name as the lookup field and default value for the label for has_one relationships, allowing multiple relations to the same class to have their own translated labels.
@pablobm
Copy link
Collaborator

pablobm commented Mar 31, 2022

Yup, I think this is correct 👍 The whole i18n setup needs a good lookover, but these incremental fixes may get us there one step at a time. Thank you!

@pablobm pablobm merged commit c3319b0 into thoughtbot:main Mar 31, 2022
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.

2 participants