Parent association for embedded document using MongoMapper

mongomapper

Solution

You do not need post_id or belongs_to :post. Instead, you can use embedded_in :post. This will make a read method for _parent_reference named post so you can say comment.post instead of comment._parent_reference.

class Comment
  include MongoMapper::EmbeddedDocument

  embedded_in :post
end

Problem

If I have: ``` class Post include MongoMapper::Document has_many :comments end ``` If I do: ``` class Comment include MongoMapper::EmbeddedDocument belongs_to :post # relevant part end ``` Does that create an association using `_root_document`/`_parent_document`, or do I have to add the (redundant) `key :post_id`?

Original source