-
-
Notifications
You must be signed in to change notification settings - Fork 810
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
Case Insensitive Sorting in Postgresql #1201
Comments
@shingz96 does See https://github.com/activerecord-hackery/ransack#search-matchers |
that is for searching, what I am looking for is sorting |
@shingz96 Hi! Did you find any workarounds for this? I'm thinking about monkey patching Ransack to be able to do something like |
I did found a possible way from this stackoverflow answer, but take note that this may break query when using DISTINCT, |
@shingz96 Ah, right! That's along the lines of what I was considering. Thank you for replying! |
Some more information here about this topic https://www.postgresql.org/docs/13/citext.html |
Copying from the SO answer https://stackoverflow.com/a/34677378 You can solve this for all string columns of a model at once by using this approach: lib/ransack_object.rbmodule RansackObject
def self.included(base)
base.columns.each do |column|
if column.type == :string
base.ransacker column.name.to_sym, type: :string do
Arel.sql("lower(#{base.table_name}.#{column.name})")
end
end
end
end
end Then include the ransack object in your model: class UserWithManyAttributes < ActiveRecord::Base
include RansackObject
end |
Thanks @seanfcarroll! |
This solution applies 'lower' to searching as well. Is there a way to only apply to sorting, handling relations? |
You can do something like this and control where you want to do lower search or sort by adding _ci to field name
|
I would like to ask that is there any possibility to have a way so that can be put in configuration to make the sorting order be done in case insensitive way in Postgresql SQL?
The text was updated successfully, but these errors were encountered: