Skip to content

Instantly share code, notes, and snippets.

@lynnfaraday
Last active March 18, 2019 05:12
Show Gist options
  • Save lynnfaraday/fa59879afaf24e5f13bd4002ce57caf3 to your computer and use it in GitHub Desktop.
Save lynnfaraday/fa59879afaf24e5f13bd4002ce57caf3 to your computer and use it in GitHub Desktop.
require 'ohm'
Ohm.redis = Redic.new("CONN_STRING")
class Photo < Ohm::Model
reference :photo_album, "PhotoAlbum"
attribute :name
index :name
end
class PhotoAlbum < Ohm::Model
collection :photos, "Photo"
attribute :name
index :name
end
def createPhotos(album, num)
num.times do |n|
p = Photo.create(name: "#{n}", photo_album: album)
end
end
def deletePhotos
Photo.all.each { |p| p.delete }
PhotoAlbum.all.each { |p| p.delete }
end
smallAlbum = PhotoAlbum.create(name: "Small")
bigAlbum = PhotoAlbum.create(name: "Big")
createPhotos(smallAlbum, 100)
createPhotos(bigAlbum, 3000)
puts "Small #{smallAlbum.photos.count}"
puts smallAlbum.photos.map { |p| p.name }.join(" ")
puts "Big #{bigAlbum.photos.count}"
puts bigAlbum.photos.map { |p| p.name }.join(" ")
deletePhotos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment