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.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/marty/monkey.rb', line 112 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
150 151 152 153 |
# File 'lib/marty/monkey.rb', line 150 def update_predecate_for_enum(table, op, value) col = Arel::Nodes::NamedFunction.new("CAST", [table.as("TEXT")]) col.matches "%#{value}%" end |