-
Notifications
You must be signed in to change notification settings - Fork 85
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
Validations create empty translations in DB #569
Comments
Please write a failing test, that's much clearer than a long explanation. |
See this failing spec: https://github.com/mrbrdo/mobility/blob/mrbrdo/spec/mobility/backends/active_record/table_spec.rb#L112 Also, I'm not sure that a fallback for |
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
Unfortunately the fix in #572 doesn't work with caching (several tests are failing on that branch). |
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
I am using fallbacks. One of my locales is "en-GB", and I think the I18n fallbacks defaults to "en" as a fallback.
However this bug exists also without fallbacks, it's just easier to explain this kind of case.
During validations, translation_for will be called:
https://github.com/shioyama/mobility/blob/master/lib/mobility/backends/active_record/table.rb#L291
It will build a translation for this "en" locale, even though this is not necessary.
Additionally I have a presence validation on the Translation class (friendly_id slug). Therefore due to this, I cannot save my models, because fallbacks is generating empty translations on the model. Even if I did not have that validation, it would create unwanted empty translations in the DB upon saving.
Temporarily I fixed it by patching generate_fallbacks to exclude the 'en' locale, but that only partly fixes it - only for models which have translations for all locales I use.
Possible solution would be for the reader to not call build, and only writer to call build. I can whiff up a PR if you think that solution is the best we can do.
The text was updated successfully, but these errors were encountered: