-
-
Save bkeepers/611612 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
>> 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 |
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
{ | |
"name": "Brandon" | |
"projects": [ | |
{"id": ObjectID(…), "name":"MongoMapper"} | |
] | |
} |
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
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