Skip to content

Instantly share code, notes, and snippets.

@benoittgt
Created September 8, 2023 10:23
Show Gist options
  • Save benoittgt/a4e8605301d8225456ed34da80bb1424 to your computer and use it in GitHub Desktop.
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
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