{"record":{"id":"73d07a68aa05aa2c","repo":"mongodb/mongoid","slug":"cannot-set-the-attr-attribute-on-the-klass-c","errorCode":null,"errorMessage":"Cannot set the %{attr} attribute on the %{klass} class.","messagePattern":"Cannot set the %(.+?) attribute on the %(.+?) class\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidDotDollarAssignment","httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields.rb","lineNumber":276,"sourceCode":"    #\n    # @return [ true | false ] If this field is dotted or dollared.\n    def dot_dollar_field?(name)\n      n = aliased_fields[name] || name\n      fields.key?(n) && (n.include?('.') || n.start_with?('$'))\n    end\n\n    # Validate whether or not the field starts with a dollar sign ($) or\n    # contains a dot/period (.).\n    #\n    # @api private\n    #\n    # @raise [ InvalidDotDollarAssignment ] If contains dots or starts with a dollar.\n    #\n    # @param [ String ] name The field name.\n    def validate_writable_field_name!(name)\n      return unless dot_dollar_field?(name)\n\n      raise Errors::InvalidDotDollarAssignment.new(self.class, name)\n    end\n\n    class << self\n      # Stores the provided block to be run when the option name specified is\n      # defined on a field.\n      #\n      # No assumptions are made about what functionality the handler might\n      # perform, so it will always be called if the `option_name` key is\n      # provided in the field definition -- even if it is false or nil.\n      #\n      # @example\n      #   Mongoid::Fields.option :required do |model, field, value|\n      #     model.validates_presence_of field if value\n      #   end\n      #\n      # @param [ Symbol ] option_name the option name to match against\n      # @param &block the handler to execute when the option is provided.\n      def option(option_name, &block)","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields.rb#L258-L294","documentation":"Error \"Cannot set the %{attr} attribute on the %{klass} class.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/fields.rb:276 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"}