Skip to content

Instantly share code, notes, and snippets.

@k2052
Created September 20, 2012 15:36
Show Gist options
  • Save k2052/3756650 to your computer and use it in GitHub Desktop.
Save k2052/3756650 to your computer and use it in GitHub Desktop.
require 'mongo'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('localhost', nil)
MongoMapper.database = 'sandbox_poly'
class Commentable
include MongoMapper::Document
many :comments, :as => :commentable
end
class Article < Commentable
key :title
end
class Product < Commentable
key :sku
end
class Comment
include MongoMapper::Document
key :text
belongs_to :commentable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment