Class: Netzke::Basepack::DataAdapters::ActiveRecordAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- Netzke::Basepack::DataAdapters::ActiveRecordAdapter
- Defined in:
- lib/marty/monkey.rb
Instance Method Summary collapse
-
#predicates_for_and_conditions(conditions) ⇒ Object
The following is a hack to get around Netzke’s broken handling of filtering on PostgreSQL enums columns.
- #update_predecate_for_enum(table, _op, value) ⇒ Object
Instance Method Details
#predicates_for_and_conditions(conditions) ⇒ Object
The following is a hack to get around Netzke’s broken handling of filtering on PostgreSQL enums columns.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/marty/monkey.rb', line 194 def predicates_for_and_conditions(conditions) return nil if conditions.empty? predicates = conditions.map do |q| q = HashWithIndifferentAccess.new(Netzke::Support.permit_hash_params(q)) attr = q[:attr] method, assoc = method_and_assoc(attr) arel_table = assoc ? Arel::Table.new(assoc.klass.table_name.to_sym) : @model.arel_table value = q['value'] op = q['operator'] attr_type = attr_type(attr) case attr_type when :datetime update_predecate_for_datetime(arel_table[method], op, value.to_date) when :string, :text update_predecate_for_string(arel_table[method], op, value) when :boolean update_predecate_for_boolean(arel_table[method], op, value) when :date update_predecate_for_rest(arel_table[method], op, value.to_date) when :enum # HACKY! monkey patching happens here... update_predecate_for_enum(arel_table[method], op, value) else update_predecate_for_rest(arel_table[method], op, value) end end # join them by AND predicates[1..-1].inject(predicates.first) { |r, p| r.and(p) } end |
#update_predecate_for_enum(table, _op, value) ⇒ Object
232 233 234 235 |
# File 'lib/marty/monkey.rb', line 232 def update_predecate_for_enum(table, _op, value) col = Arel::Nodes::NamedFunction.new('CAST', [table.as('TEXT')]) col.matches "%#{value}%" end |