{"record":{"id":"978d08db9d2d66d5","repo":"mongodb/mongoid","slug":"ambiguous-associations-candidates-defined-on-978d08","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/has_many.rb","lineNumber":221,"sourceCode":"        private\n\n        def default_foreign_key_field\n          @default_foreign_key_field ||= \"#{inverse}#{FOREIGN_KEY_SUFFIX}\"\n        end\n\n        def polymorphic_inverses(_other)\n          [ as ]\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          if matches.size > 1\n            return [ default_inverse.name ] if default_inverse\n\n            raise Errors::AmbiguousRelationship.new(relation_class, @owner_class, name, matches)\n          end\n          matches.collect { |m| m.name } unless matches.blank?\n        end\n\n        def default_primary_key\n          PRIMARY_KEY_DEFAULT\n        end\n\n        def query_criteria(object, base)\n          crit = klass.criteria\n          crit = crit.apply_scope(scope)\n          crit = crit.where(foreign_key => object)\n          crit = with_polymorphic_criterion(crit, base)\n          crit.association = self\n          crit.parent_document = base\n          with_ordering(crit)\n        end\n","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/referenced/has_many.rb#L203-L239","documentation":"Error \"Ambiguous associations %{candidates} defined on %{klass}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/referenced/has_many.rb:221 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"}