{"record":{"id":"c72fe80f7969828b","repo":"mongodb/mongoid","slug":"when-adding-a-n-klass-to-base-name-mong","errorCode":null,"errorMessage":"When adding a(n) %{klass} to %{base}#%{name}, Mongoid could not determine the inverse foreign key to set. The attempted key was '%{inverse}'.","messagePattern":"When adding a\\(n\\) %(.+?) to %(.+?)#%(.+?), Mongoid could not determine the inverse foreign key to set\\. The attempted key was '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::InverseNotFound","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/bindable.rb","lineNumber":54,"sourceCode":"        end\n      end\n\n      private\n\n      # Check if the inverse is properly defined.\n      #\n      # @api private\n      #\n      # @example Check the inverse definition.\n      #   binding.check_inverse!(doc)\n      #\n      # @param [ Document ] doc The document getting bound.\n      #\n      # @raise [ Errors::InverseNotFound ] If no inverse found.\n      def check_inverse!(doc)\n        return if _association.bindable?(doc)\n\n        raise Errors::InverseNotFound.new(\n          _base.class,\n          _association.name,\n          doc.class,\n          _association.foreign_key\n        )\n      end\n\n      # Remove the associated document from the inverse's association.\n      #\n      # @param [ Document ] doc The document to remove.\n      def remove_associated(doc)\n        return unless inverse = _association.inverse(doc)\n\n        if _association.many?\n          remove_associated_many(doc, inverse)\n        elsif _association.in_to?\n          remove_associated_in_to(doc, inverse)\n        end","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/bindable.rb#L36-L72","documentation":"Error \"When adding a(n) %{klass} to %{base}#%{name}, Mongoid could not determine the inverse foreign key to set. The attempted key was '%{inverse}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/bindable.rb:54 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"}