{"record":{"id":"6a3c67a24b3cb7d2","repo":"mongodb/mongoid","slug":"defining-an-association-named-name-is-not-all-6a3c67","errorCode":null,"errorMessage":"Defining an association named '%{name}' is not allowed.","messagePattern":"Defining an association named '%(.+?)' is not allowed\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidRelation","httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields/validators/macro.rb","lineNumber":49,"sourceCode":"        # @param [ Symbol ] name The field name.\n        # @param [ Hash ] options The provided options.\n        def validate(klass, name, options)\n          validate_field_name(klass, name)\n          validate_name_uniqueness(klass, name, options)\n          validate_options(klass, name, options)\n        end\n\n        # Validate the association definition.\n        #\n        # @example Validate the association definition.\n        #   Macro.validate(Model, :name)\n        #\n        # @param [ Class ] klass The model class.\n        # @param [ Symbol ] name The field name.\n        # @param [ Hash ] options The provided options.\n        def validate_relation(klass, name, _options = {})\n          [ name, :\"#{name}?\", :\"#{name}=\" ].each do |n|\n            raise Errors::InvalidRelation.new(klass, n) if Mongoid.destructive_fields.include?(n)\n          end\n        end\n\n        # Determine if the field name is valid, if not raise an error.\n        #\n        # @example Check the field name.\n        #   Macro.validate_field_name(Model, :name)\n        #\n        # @param [ Class ] klass The model class.\n        # @param [ Symbol ] name The field name.\n        #\n        # @raise [ Errors::InvalidField ] If the name is not allowed.\n        #\n        # @api private\n        def validate_field_name(klass, name)\n          [ name, :\"#{name}?\", :\"#{name}=\" ].each do |n|\n            raise Errors::InvalidField.new(klass, name, n) if Mongoid.destructive_fields.include?(n)\n          end","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields/validators/macro.rb#L31-L67","documentation":"Error \"Defining an association named '%{name}' is not allowed.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/fields/validators/macro.rb:49 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"}