Created
September 8, 2023 10:23
-
-
Save benoittgt/a4e8605301d8225456ed34da80bb1424 to your computer and use it in GitHub Desktop.
Force bind parameter and prepared statement with unaccent query with ActiveRecord and Arel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bind_param = Arel::Nodes::BindParam.new(ActiveRecord::Relation::QueryAttribute.new('search_text', "%Nate%", ActiveRecord::Type::String.new)) | |
Customer.where(Customer.arel_table["search_text"].matches( | |
Arel::Nodes::NamedFunction.new('unaccent', [Arel::Nodes::build_quoted(bind_param)]), | |
nil, | |
true # case insensitive | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment