{"record":{"id":"5b92025917a2290f","repo":"mongodb/mongoid","slug":"defining-a-scope-of-value-value-on-klass-is","errorCode":null,"errorMessage":"Defining a scope of value %{value} on %{klass} is not allowed.","messagePattern":"Defining a scope of value %(.+?) on %(.+?) is not allowed\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidScope","httpStatus":null,"severity":"error","filePath":"lib/mongoid/scopable.rb","lineNumber":268,"sourceCode":"          'and will ignore the declared scope.'\n        )\n      end\n\n      # Checks if the intended scope is a valid object, either a criteria or\n      # proc with a criteria.\n      #\n      # @api private\n      #\n      # @example Check if the scope is valid.\n      #   Model.check_scope_validity({})\n      #\n      # @param [ Object ] value The intended scope.\n      #\n      # @raise [ Errors::InvalidScope ] If the scope is not a valid object.\n      def check_scope_validity(value)\n        return if value.respond_to?(:call)\n\n        raise Errors::InvalidScope.new(self, value)\n      end\n\n      # Defines the actual class method that will execute the scope when\n      # called.\n      #\n      # @api private\n      #\n      # @example Define the scope class method.\n      #   Model.define_scope_method(:active)\n      #\n      # @param [ Symbol ] name The method/scope name.\n      #\n      # @return [ Method ] The defined method.\n      def define_scope_method(name)\n        singleton_class.class_eval do\n          define_method(name) do |*args, **kwargs|\n            scoping = _declared_scopes[name]\n            scope = instance_exec(*args, **kwargs, &scoping[:scope])","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/scopable.rb#L250-L286","documentation":"Error \"Defining a scope of value %{value} on %{klass} is not allowed.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/scopable.rb:268 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"}