-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Example:
class User
include Mongoid::Document
embeds_one :address
end
class Address
include Mongoid::Document
embedded_in :user
after_initialize :say_owner
def say_owner
puts "I'm embedded in #
"
end
end
>> user = User.new
=> #<User _id: 4d9d532a8eed0498b7000003, _type: nil, _id: BSON::ObjectId('4d9d532a8eed0498b7000003')>
>> user.build_address
I'm embedded in nil
=> #<Address _id: 4d9d532d8eed0498b7000004, _type: nil, _id: BSON::ObjectId('4d9d532d8eed0498b7000004')>
>> user.address.say_owner
I'm embedded in #<User _id: 4d9d532a8eed0498b7000003, _type: nil, _id: BSON::ObjectId('4d9d532a8eed0498b7000003')>
=> nil