Module: Dynamometer::DynamicAttributesInWhere
- Defined in:
- lib/dynamometer/dynamic_attributes_in_where.rb
Instance Method Summary collapse
Instance Method Details
#where(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/dynamometer/dynamic_attributes_in_where.rb', line 4 def where(*args) return super if !args.first.is_a?(Hash) || args.first.keys.any? { |x| x.is_a?(Hash) } regulars, dynamics = klass.partition_wheres(args.first) if dynamics.empty? super else super(regulars).where_dynamic_attributes(dynamics) end end |
#where_dynamic_attributes(filters) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/dynamometer/dynamic_attributes_in_where.rb', line 14 def where_dynamic_attributes(filters) spawn.tap do |new_rel| (filters || {}).each do |k, v| new_rel.where_values += build_where("dynamic_attributes @> hstore(?, ?)", [k, v]) end end end |