Module: Shoppy::Concerns::Models::Hashable::ClassMethods

Defined in:
app/models/shoppy/concerns/models/hashable.rb

Overview

These are shared mothods, a.k.a class methods

Instance Method Summary collapse

Instance Method Details

#by_hash_key(key) ⇒ Object

Query all model instances that have a given key, regardless of the valiue for that key.



49
50
51
# File 'app/models/shoppy/concerns/models/hashable.rb', line 49

def by_hash_key(key)
  self.where("hash_data ? :key", key: key)
end

#by_hash_key_value(key, value) ⇒ Object

Query all model instance sthat have a given key/value pair.



55
56
57
58
# File 'app/models/shoppy/concerns/models/hashable.rb', line 55

def by_hash_key_value(key, value)
  kv = key + "=>" + value
  self.where("hash_data @> :kv", kv: kv)
end