Module: ScopedSearch::Adapter::MysqlAdapter::FieldInstanceMethods
- Defined in:
- lib/scoped_search/adapters.rb
Instance Method Summary collapse
-
#to_sql(operator = nil) {|:include, relation| ... } ⇒ Object
Monkey patch Field#to_sql method to ensure that comparisons using :eq / :ne are case sensitive by adding a BINARY operator in front of the field name.
Instance Method Details
#to_sql(operator = nil) {|:include, relation| ... } ⇒ Object
Monkey patch Field#to_sql method to ensure that comparisons using :eq / :ne are case sensitive by adding a BINARY operator in front of the field name.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/scoped_search/adapters.rb', line 19 def to_sql(operator = nil, &block) # Normal implementation yield(:include, relation) if relation field_name = definition.klass.connection.quote_table_name(klass.table_name) + "." + definition.klass.connection.quote_column_name(field) # Add BINARY operator if the field is textual and = or <> is used. field_name = "BINARY #{field_name}" if textual? && [:ne, :eq].include?(operator) return field_name end |