-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.1.2, 7.1.4
-
Component/s: Associations
-
None
-
Environment:MongoDB 4.0
-
Fully Compatible
Here is a reproducible code.
require 'bundler/inline' require 'tempfile' gemfile do source 'https://rubygems.org' gem 'mongoid', '7.1.4' end Tempfile.open(%w(config.yml)) do |f| f.write(<<~YAML) development: clients: default: uri: mongodb://mongo/test YAML f.flush Mongoid.load!(f.path, 'development') end class Parent include Mongoid::Document include Mongoid::Timestamps has_one :child, dependent: :destroy end class Child include Mongoid::Document include Mongoid::Timestamps belongs_to :parent end parent = Parent.create child = Child.create(parent: parent) p Child.find(child.id) #=> returns the child parent.child = child p Child.find(child.id) #=> raises Mongoid::Errors::DocumentNotFound
This also happens with a polymorphic association. This doesn't happen without the dependent: :destroy option.