{"record":{"id":"d9a8852ced9e5588","repo":"CanCanCommunity/cancancan","slug":"this-model-adapter-does-not-support-matching-on-a-d9a885","errorCode":null,"errorMessage":"This model adapter does not support matching on a specific condition.","messagePattern":"This model adapter does not support matching on a specific condition\\.","errorType":"exception","errorClass":"CanCan::NotImplemented","httpStatus":null,"severity":"error","filePath":"lib/cancan/model_adapters/abstract_adapter.rb","lineNumber":63,"sourceCode":"      # If this returns true then nested_subject_matches_conditions? will be called.\n      def self.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions)\n        false\n      end\n\n      # Override if override_nested_subject_conditions_matching? returns true\n      def self.nested_subject_matches_conditions?(_parent, _child, _all_conditions)\n        raise NotImplemented, 'This model adapter does not support matching on a nested subject.'\n      end\n\n      # Used to determine if this model adapter will override the matching behavior for a specific condition.\n      # If this returns true then matches_condition? will be called. See Rule#matches_conditions_hash\n      def self.override_condition_matching?(_subject, _name, _value)\n        false\n      end\n\n      # Override if override_condition_matching? returns true\n      def self.matches_condition?(_subject, _name, _value)\n        raise NotImplemented, 'This model adapter does not support matching on a specific condition.'\n      end\n\n      def initialize(model_class, rules)\n        @model_class = model_class\n        @rules = rules\n      end\n\n      def database_records\n        # This should be overridden in a subclass to return records which match @rules\n        raise NotImplemented, 'This model adapter does not support fetching records from the database.'\n      end\n    end\n  end\nend\n","sourceCodeStart":45,"sourceCodeEnd":78,"githubUrl":"https://github.com/CanCanCommunity/cancancan/blob/8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828/lib/cancan/model_adapters/abstract_adapter.rb#L45-L78","documentation":"AbstractAdapter#matches_condition? (lib/cancan/model_adapters/abstract_adapter.rb:63) raises CanCan::NotImplemented. It is only called when the adapter's override_condition_matching?(subject, name, value) returns true — the per-condition override hook — so this error means an adapter promised per-condition matching for some (subject, attribute) pair but never implemented the method.","triggerScenarios":"A custom adapter with special handling like def self.override_condition_matching?(subject, name, value); name == :geometry; end but no matches_condition? implementation; then a rule containing that condition (can :read, Map, geometry: polygon) is instance-checked via can?/authorize!.","commonSituations":"Adapters adding support for non-column condition types (arrays, JSON columns, geo types) and forgetting the matcher half of the pair; partial vendored forks of the ActiveRecord adapter.","solutions":["Implement self.matches_condition?(subject, name, value) for every (name, value) shape your override_condition_matching? claims.","Or narrow override_condition_matching? so it returns true only for the cases you actually handle, letting others fall through to default matching.","If using a third-party adapter: upgrade it or replace the exotic condition with a plain attribute/block condition."],"exampleFix":"# before (custom adapter)\ndef self.override_condition_matching?(_subject, name, _value)\n  true # claims every condition, implements none\nend\n\n# after\ndef self.override_condition_matching?(_subject, name, _value)\n  false # default matching handles regular columns\nend\n# and only flip to true for specific names you implement in\n# def self.matches_condition?(subject, name, value); ...; end","handlingStrategy":"validation","validationCode":"# adapter authors: scope the claim to conditions you really implement\nclass MyAdapter < CanCan::ModelAdapters::AbstractAdapter\n  HANDLED = %i[geometry].freeze\n  def self.override_condition_matching?(_subject, name, _value)\n    HANDLED.include?(name.to_sym) # false elsewhere -> default matching\n  end\nend","typeGuard":"def adapter_supports_condition?(adapter, subject, name, value)\n  !adapter.override_condition_matching?(subject, name, value) || adapter.method(:matches_condition?).owner != CanCan::ModelAdapters::AbstractAdapter\nend","tryCatchPattern":"begin\n  can?(:read, @map)\nrescue CanCan::NotImplemented => e\n  Rails.logger.error(\"adapter incomplete: #{e.message}\")\n  false\nend","preventionTips":["Never return true unconditionally from override_condition_matching?.","Pair every override_condition_matching? branch with a spec for matches_condition?.","Replace exotic conditions with plain attributes or blocks when the adapter cannot match them."],"tags":["model-adapter","condition-matching","not-implemented","cancancan","ruby"],"backgroundTag":"unimplemented-adapter-method","analyzedSha":"8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828","analyzedAt":"2026-08-21T20:05:55.000Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}