Created
June 5, 2010 20:44
-
-
Save arekt/426978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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