How to reproduce:
require 'rubygems'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("mongoid-history")
end
class Post
include Mongoid::Document
field :title
field :body
embeds_many :comments
end
class Comment
include Mongoid::Document
field :title
field :body
embedded_in :post, :inverse_of => :comments
end
post = Post.create(:title => "test", :body => "test")
comment = post.comments.create(:title => "test", :body => "test")
comment.reload
Output:
Mongoid::Errors::InvalidCollection: Access to the collection for Comment is not allowed since it is an embedded document, please access a collection from the root document.
from /Users/aqian/.rvm/gems/ruby-1.9.2-p180@moe/gems/mongoid-2.0.0.rc.7/lib/mongoid/collections.rb:21:in `collection'
from /Users/aqian/.rvm/gems/ruby-1.9.2-p180@moe/gems/mongoid-2.0.0.rc.7/lib/mongoid/collections.rb:11:in `collection'
from /Users/aqian/.rvm/gems/ruby-1.9.2-p180@moe/gems/mongoid-2.0.0.rc.7/lib/mongoid/document.rb:145:in `reload'
from (irb):28
from /Users/aqian/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'