{"record":{"id":"1cb5889bc3dfa6f3","repo":"mongodb/mongoid","slug":"ambiguous-associations-candidates-defined-on-1cb588","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_and_belongs_to_many.rb","lineNumber":257,"sourceCode":"\n        def create_foreign_key_field!\n          inverse_class.aliased_associations[foreign_key] = name.to_s\n          @owner_class.field(\n            foreign_key,\n            type: FOREIGN_KEY_FIELD_TYPE,\n            identity: true,\n            overwrite: true,\n            association: self,\n            default: nil\n          )\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 } unless matches.blank?\n        end\n\n        def with_ordering(criteria)\n          if order\n            criteria.order_by(order)\n          else\n            criteria\n          end\n        end\n\n        def query_criteria(id_list)\n          crit = relation_class.criteria\n          crit = if id_list\n                   crit = crit.apply_scope(scope)\n                   # A nil in the stored key array would match every document\n                   # whose primary key is null or absent, returning documents","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/referenced/has_and_belongs_to_many.rb#L239-L275","documentation":"Error \"Ambiguous associations %{candidates} defined on %{klass}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/referenced/has_and_belongs_to_many.rb:257 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"}