Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created October 5, 2010 14:09
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 bkeepers/611612 to your computer and use it in GitHub Desktop.
Save bkeepers/611612 to your computer and use it in GitHub Desktop.
>> u = User.first
=> …
>> p = u.projects.first
=> …
>> p.name # Read from embedded doc
=> "MongoMapper"
>> p.description
=> "A Ruby Object Mapper for Mongo" # loads lazy attribute
{
"name": "Brandon"
"projects": [
{"id": ObjectID(…), "name":"MongoMapper"}
]
}
class User
include MongoMapper::Document
key :name
many :projects, :embed => :name
end
class Project
include MongoMapper::Document
key :name
key :description
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment