Skip to content

Instantly share code, notes, and snippets.

@arekt
Created June 5, 2010 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arekt/426978 to your computer and use it in GitHub Desktop.
Save arekt/426978 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('localhost',27017)
MongoMapper.database = "test"
class User
include MongoMapper::Document
key :name, String
many :ideas do
def roots
map do |i|
i.idea_roots.inspect
end
end
end
end
class Idea
include MongoMapper::Document
key :content, String
key :user_id, ObjectId
def idea_roots
"#{self.content} roots... "
end
belongs_to :user
end
User.collection.remove
Idea.collection.remove
user = User.new(:name => "1")
user.ideas = [Idea.new(:content => "one"), Idea.new(:content=>"two"), Idea.new(:content => "three")]
user.save
puts User.first.ideas.roots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment