Created
December 5, 2011 05:28
-
-
Save brianhempel/1432429 to your computer and use it in GitHub Desktop.
Example code tested on the mmconsole regarding http://groups.google.com/group/mongomapper/browse_thread/thread/74239f58e51042ef
This file contains hidden or 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 | |
def profile | |
person.profile | |
end | |
one :person, :class_name => 'Person', :foreign_key => :owner_id | |
end | |
class Person | |
include MongoMapper::Document | |
key :email, String, :unique => true | |
key :url, String | |
key :owner_id, ObjectId | |
belongs_to :owner, :class_name => 'User' | |
one :profile, :class_name => 'Profile' | |
end | |
class Profile | |
include MongoMapper::EmbeddedDocument | |
key :first_name, String | |
key :last_name, String | |
key :image_url, String | |
end | |
my_user = User.create(:person => Person.new(:profile => Profile.new)) | |
my_user.profile # => #<Profile _id: BSON::ObjectId('4edc555578fca28259000001')> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment