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

Add order by for translated fields #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

kule
Copy link

@kule kule commented Jun 8, 2018

I still need to review the quoting for the order by (currently it's hard-coded), there's probably a way to quote them properly using AR methods. However just checking would you be interested in accepting this functionality?

@frantisekrokusek
Copy link
Collaborator

I still need to review the quoting for the order by (currently it's hard-coded), there's probably a way to quote them properly using AR methods. However just checking would you be interested in accepting this functionality?

I like the idea. Can you please improve it as you proposed! ;) Ping me when it is ready for you!

@dalezak
Copy link

dalezak commented Aug 2, 2020

Any ETA on when this PR will be merged?

Copy link
Contributor

@frantisekrokusekpa frantisekrokusekpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Last few things.

Comment on lines +76 to +84
To order records using translations without constructing JSON queries by hand:

```ruby
Post.order_by_title_translation # => #<ActiveRecord::Relation ...>
Post.order_by_title_translation(:asc) # => #<ActiveRecord::Relation ...>
Post.order_by_title_translation(:desc) # => #<ActiveRecord::Relation ...>
Post.order_by_title_translation(:desc, :he) # => #<ActiveRecord::Relation ...>
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify the defaults (direction and locale) in the README please?

@@ -48,6 +48,16 @@ def translates(*attrs)
where("#{quoted_translation_store} @> :translation::jsonb", translation: translation_hash.to_json)
end
end

define_singleton_method "order_by_#{attr_name}_translation" do |direction = :asc, locale = I18n.locale|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "order_by_#{attr_name}#{SUFFIX}"? Would be more conventional.

@frantisekrokusekpa
Copy link
Contributor

Any ETA on when this PR will be merged?

End of August probably.

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.

5 participants