Skip to content

Instantly share code, notes, and snippets.

@brianhempel
Created December 5, 2011 05:28
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 brianhempel/1432429 to your computer and use it in GitHub Desktop.
Save brianhempel/1432429 to your computer and use it in GitHub Desktop.
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