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

Cyclic embeds interfering with inherited models

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0, 5.2.0
    • Affects Version/s: 5.1.1
    • Component/s: None
    • None
    • Environment:
      gem 'rails', '4.2.4'
      gem "mongoid", "~>5.1"

      It appears that cyclic embeds are interfering with mongoid's ability to interface with mongo when inheritance is involved.

      Example:

      Place.rb
      class Places::Place
        include Mongoid::Document
        include Mongoid::Timestamps
        
        store_in collection: "places"
      
        field :name,         type: String,
      
        recursively_embeds_one
      end
      
      class Places::BurgerJoint < Places::Place
      end
      

      In prior versions of mongoid, we were able to query the database and access the `child_place` as expected on both `Places::Place` and `Places::BurgerJoint`. Now when querying the database, nothing happens.

      Console.rb
        Mongo::Logger.logger = Logger.new($stdout)
        Mongoid.logger=Logger.new($stdout)
      
        Places::Place.first
        => nil
      

      Note the complete lack of logging, queries, etc.
      However, if we remove `recursively_embeds_one`, then all is well.

      Console.rb
        Mongo::Logger.logger = Logger.new($stdout)
        Mongoid.logger=Logger.new($stdout)
      
        Places::Place.first
        => D, [2017-01-24T15:12:07.145000 #38947] DEBUG -- : MONGODB | Topology type 'unknown' initializing.
        D, [2017-01-24T15:12:07.157000 #38947] DEBUG -- : MONGODB | Server localhost:27017 initializing.
        D, [2017-01-24T15:12:07.255000 #38947] DEBUG -- : MONGODB | Topology type 'unknown' changed to type 'single'.
        D, [2017-01-24T15:12:07.256000 #38947] DEBUG -- : MONGODB | Server description for localhost:27017 changed from 'unknown' to 'standalone'.
        D, [2017-01-24T15:12:07.257000 #38947] DEBUG -- : MONGODB | There was a change in the members of the 'single' topology.
        D, [2017-01-24T15:12:07.328000 #38947] DEBUG -- : MONGODB | localhost:27017 | sitata_development.find | STARTED | {"find"=>"places", "filter"=>{}, "limit"=>1, "singleBatch"=>true}
        D, [2017-01-24T15:12:07.339000 #38947] DEBUG -- : MONGODB | localhost:27017 | sitata_development.find | SUCCEEDED | 0.009999999999999998s
        => #<Places::BurgerJoint _id: 54f35e5528bfd49851000791, etc.. >
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            astjohn Adam St. John
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: