Method: Sohm::Model.find
- Defined in:
- lib/sohm.rb
.find(dict) ⇒ Object
Find values in indexed fields.
Example:
class User < Sohm::Model
attribute :email
attribute :name
index :name
attribute :status
index :status
index :provider
index :tag
def provider
email[/@(.*?).com/, 1]
end
def tag
["ruby", "python"]
end
end
u = User.create(name: "John", status: "pending", email: "[email protected]")
User.find(provider: "me", name: "John", status: "pending").include?(u)
# => true
User.find(:tag => "ruby").include?(u)
# => true
User.find(:tag => "python").include?(u)
# => true
Due to restrictions in Codis, we only support single-index query. If you want to query based on multiple fields, you can make an index based on all the fields.
616 617 618 619 620 621 622 623 624 |
# File 'lib/sohm.rb', line 616 def self.find(dict) keys = filters(dict) if keys.size == 1 Sohm::Set.new(keys.first, key, self) else raise NotSupported end end |