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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With