Dependents are tracked incorrectly through sibling documents

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 7.0.2
    • Affects Version/s: 7.0.1
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It seems that declaring dependents in one document type also adds these dependents to any sibling class. Attempting to delete or destroy an instance of the sibling therefore fails.

      Example:

      class ReportCard
        include Mongoid::Document
      end
      
      class User
        include Mongoid::Document
      end
      
      class Student < User
        has_many :report_cards, class_name: 'ReportCard', dependent: :destroy
      end
      
      class CollegeUser < User
      end
      
      def main
        c = CollegeUser.create
        puts c.dependents
        c.destroy
      end
      

      The output of the above is as follows:

      #<Mongoid::Association::Referenced::HasMany:0x00007fdd5ad031a0>
      NoMethodError: undefined method `report_cards' for #<CollegeUser2:0x00007fdd50872cd0>
      from /Users/luke/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/mongoid-7.0.1/lib/mongoid/association/depending.rb:86:in `_dependent_destroy!'
      

            Assignee:
            Samuel Rossi (Inactive)
            Reporter:
            Luke Lovett
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: