Skip to content

Instantly share code, notes, and snippets.

@dewski
Created March 20, 2010 02:25
Show Gist options
  • Select an option

  • Save dewski/338409 to your computer and use it in GitHub Desktop.

Select an option

Save dewski/338409 to your computer and use it in GitHub Desktop.
class User
include MongoMapper::Document
key :name, String
# etc
many :addresses
end
class Address
# Used for things that don't need associations
include MongoMapper::EmbeddedDocument
key :street, String
key :zip, Integer, :length => 5
# etc
# I think there is an enum kind of thing for this
key :state, String
end
class Item
include MongoMapper::Document
key :name, String
key :user_id, ObjectId
key :likes_ids, Array
key :_type, Object
many :likes
end
class Picture < Item
key :url, String
key :rating, Integer
end
class Video < Item
key :url, String, :required => true
key :length, Integer, :default => 0
end
p = Picture.new({ ... }).save
v = Video.new({ ... }).save
=> Item.all
# [Picture, Video]
=> Video.all
# [Video]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment