Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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