{"record":{"id":"a459c731d9bc794e","repo":"mongodb/mongoid","slug":"overwriting-existing-field-name-in-class-klas","errorCode":null,"errorMessage":"Overwriting existing field #{name} in class #{klass.name}.","messagePattern":"Overwriting existing field #(.+?) in class #(.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields/validators/macro.rb","lineNumber":88,"sourceCode":"        private\n\n        # Determine if the field name is unique, if not raise an error.\n        #\n        # @example Check the field name.\n        #   Macro.validate_name_uniqueness(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        #\n        # @raise [ Errors::InvalidField ] If the name is not allowed.\n        #\n        # @api private\n        def validate_name_uniqueness(klass, name, options)\n          return unless !options[:overwrite] && klass.fields.keys.include?(name.to_s)\n          raise Errors::InvalidField.new(klass, name, name) if Mongoid.duplicate_fields_exception\n\n          Mongoid.logger.warn(\"Overwriting existing field #{name} in class #{klass.name}.\") if Mongoid.logger\n        end\n\n        # Validate that the field options are allowed.\n        #\n        # @api private\n        #\n        # @example Validate the field options.\n        #   Macro.validate_options(Model, :name, { localized: true })\n        #\n        # @param [ Class ] klass The model class.\n        # @param [ Symbol ] name The field name.\n        # @param [ Hash ] options The provided options.\n        #\n        # @raise [ Errors::InvalidFieldOption ] If an option is invalid.\n        def validate_options(klass, name, options)\n          options.keys.each do |option|\n            if !OPTIONS.include?(option) && !Fields.options.include?(option)\n              raise Errors::InvalidFieldOption.new(klass, name, option, OPTIONS)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields/validators/macro.rb#L70-L106","documentation":"Error \"Overwriting existing field #{name} in class #{klass.name}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/fields/validators/macro.rb:88 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"}