{"record":{"id":"4a95c3defa95793c","repo":"mongodb/mongoid","slug":"ambiguous-associations-candidates-defined-on-4a95c3","errorCode":null,"errorMessage":"Ambiguous associations %{candidates} defined on %{klass}.","messagePattern":"Ambiguous associations %(.+?) defined on %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::AmbiguousRelationship","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/referenced/belongs_to.rb","lineNumber":223,"sourceCode":"        end\n\n        def polymorphic_inverses(other = nil)\n          return unless other\n\n          matches = other.relations.values.select do |rel|\n            relation_complements.include?(rel.class) &&\n              rel.as == name &&\n              rel.relation_class_name == inverse_class_name\n          end\n          matches.collect { |m| m.name }\n        end\n\n        def determine_inverses(other)\n          matches = (other || relation_class).relations.values.select do |rel|\n            relation_complements.include?(rel.class) &&\n              rel.relation_class_name == inverse_class_name\n          end\n          raise Errors::AmbiguousRelationship.new(relation_class, @owner_class, name, matches) if matches.size > 1\n\n          matches.collect { |m| m.name }\n        end\n\n        # If set to true, then the associated object will be validated when this object is saved\n        def require_association?\n          required = @options[:required] if @options.key?(:required)\n          required = !@options[:optional] if @options.key?(:optional) && required.nil?\n          required.nil? ? Mongoid.belongs_to_required_by_default : required\n        end\n\n        def create_foreign_key_field!\n          @owner_class.field(\n            foreign_key,\n            type: FOREIGN_KEY_FIELD_TYPE,\n            identity: true,\n            overwrite: true,\n            association: self,","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/referenced/belongs_to.rb#L205-L241","documentation":"Error \"Ambiguous associations %{candidates} defined on %{klass}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/referenced/belongs_to.rb:223 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"}