-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.0.1
-
Component/s: None
-
Labels:
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!'
- is depended on by
-
MONGOID-4600 Release Mongoid 7.0.2
- Closed