Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2010 02:01
Show Gist options
  • Save anonymous/339731 to your computer and use it in GitHub Desktop.
Save anonymous/339731 to your computer and use it in GitHub Desktop.
require 'ohm'
Ohm.connect(:host => '127.0.0.1')
class ManyAttributes < Ohm::Model
attribute :attr1
attribute :attr2
attribute :attr3
attribute :attr4
index :attr1
index :attr2
index :attr3
index :attr4
end
ms = ManyAttributes.all; ms.each{|m| m.delete}
ma = ManyAttributes.new(:attr1 => 'a', :attr2 => 'b', :attr3 => 'c', :attr4 => 'd')
ma.save
attrs = ManyAttributes.find(:attr1 => 'a')
puts attrs.inspect
raise "first find does not fail" unless attrs.size == 1
attrs = attrs.find(:attr2 => 'b')
raise "second find is ok" unless attrs.size == 1
attrs = attrs.find(:attr3 => 'c')
raise "third find on same data set fails" unless attrs.size == 1
attrs = attrs.find(:attr4 => 'd')
raise unless attrs.size == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment