-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add order_by feature #39
base: master
Are you sure you want to change the base?
Conversation
ping @robworley ? :) |
Firstly, thanks for your work on this 👍. I'm just not sure I want to get into this kind of generic API because it's hard to say where the scope of this translation gem will stop... ordering, querying etc. Somehow it never quite feels like first-class/proper ActiveRecord 😐. |
I think that the basic functionality should be easily accessible (find, order) - in this case you have to write quite complex code to make simple order by translation. And for me, I have to always check how can I even do that since I don't use db arrays too often 😉 |
Actually, I would use this feature too. It's fairly common requirement and the implementation is not trivial. |
I really like that feature too, but in it's current version it is not enough, at least for me. I used your code as a starting point to "coalesce" all fallback translations and use that as Perhaps updating the readme with ordering instructions would be a nice compromise until the scope of hstore_translate is properly defined ⏳ |
Would like this one too. I mostly add stuff like this:
Which of course doesn't work in this case. @daniel-rikowski mind sharing how you solved this without using this modification? |
Ok found how to do this pretty easily:
|
@rept This still won't work with fallbacks. Imagine this fallback configuration: I18n.fallbacks[I18n.locale] == [:'de-DE', :de, :en] And these database records: [
{ name_translations: { 'de-DE' => 'Kanarienvogel', 'en-US' => 'Canary' },
{ name_translations: { 'de' => 'März', 'en' => 'March' },
{ name_translations: { 'en' => 'Wikipedia' },
] Considering 'Kanarienvogel'
NULL -- should be 'März'
NULL -- should be 'Wikipedia' To achive correct sorting with fallbacks you have to generate a dynamic SQL statement which takes SELECT ... ORDER BY COALESCE(
name_translations -> 'de-DE',
name_translations -> 'de',
name_translations -> 'en') I've created a Gist with my - rather hacky - implementation. Use at your own risk! Example: Book.order_translated(:title)
Author.references(:books).order_translated(books: :title) |
Any plans on getting this integrated in the main branch? |
Simple shortcut which allows to order by translated column as described in readme.