{"record":{"id":"92215edb43b6c47d","repo":"mongodb/mongoid","slug":"cannot-destroy-document-because-of-dependent","errorCode":null,"errorMessage":"Cannot destroy %{document} because of dependent '%{relation}'.","messagePattern":"Cannot destroy %(.+?) because of dependent '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::DeleteRestriction","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/depending.rb","lineNumber":127,"sourceCode":"        return unless relation = without_autobuild { send(association.name) }\n\n        if relation.is_a?(Enumerable)\n          relation.entries\n          relation.each { |doc| doc.destroy }\n        else\n          relation.destroy\n        end\n      end\n\n      def _dependent_nullify!(association)\n        return unless relation = without_autobuild { send(association.name) }\n\n        relation.nullify\n      end\n\n      def _dependent_restrict_with_exception!(association)\n        if (relation = without_autobuild { send(association.name) }) && !relation.blank?\n          raise Errors::DeleteRestriction.new(relation, association.name)\n        end\n      end\n\n      def _dependent_restrict_with_error!(association)\n        return unless (relation = without_autobuild { send(association.name) }) && !relation.blank?\n\n        errors.add(association.name, :destroy_restrict_with_error_dependencies_exist)\n        throw(:abort, false)\n      end\n    end\n  end\nend\n","sourceCodeStart":109,"sourceCodeEnd":140,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/depending.rb#L109-L140","documentation":"Error \"Cannot destroy %{document} because of dependent '%{relation}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/depending.rb:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}