class User
include MongoMapper::Document
one :person, :class_name => 'Person', :foreign_key => :owner_id
end
class Person
include MongoMapper::Document
include ROXML
xml_accessor :_id
xml_accessor :email
xml_accessor :url
xml_accessor :profile, :as => Profile
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
include ROXML
xml_reader :person_id
xml_accessor :first_name
xml_accessor :last_name
xml_accessor :image_url
key :first_name, String
key :last_name, String
key :image_url, String
end
jon
blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
rahul chandra said the following on 12/4/11 12:25 PM:
my_user.person.profile
If you want to abbreviate that, you can define a profile method on User...
def profile
person.profile
end
Brian
> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en
Showing /home/rahul/Rails_projects/staytuned/app/views/dashboards/index.html.haml where line #3 raised:
undefined method `profile' for nil:NilClass
Extracted source (around line #3):
1: - if user_signed_in?
2: %h1#user_name
3: = link_to current_user.real_name, root_path
4: /%span= title_for_page
5: %h3#latest_message
6: = my_latest_message