Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-737

reloading embeded document causes Mongoid::Errors::InvalidCollection

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.2
    • Affects Version/s: None
    • Component/s: None

      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>'

            Assignee:
            Unassigned Unassigned
            Reporter:
            aq1018 aq1018
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: