{"record":{"id":"24969c3789812a1a","repo":"CanCanCommunity/cancancan","slug":"this-model-adapter-does-not-support-matching-on-a-24969c","errorCode":null,"errorMessage":"This model adapter does not support matching on a nested subject.","messagePattern":"This model adapter does not support matching on a nested subject\\.","errorType":"exception","errorClass":"CanCan::NotImplemented","httpStatus":null,"severity":"error","filePath":"lib/cancan/model_adapters/abstract_adapter.rb","lineNumber":52,"sourceCode":"      def self.matches_conditions_hash?(_subject, _conditions)\n        raise NotImplemented, 'This model adapter does not support matching on a conditions hash.'\n      end\n\n      # Override if parent condition could be under a different key in conditions\n      def self.parent_condition_name(parent, _child)\n        parent.class.name.downcase.to_sym\n      end\n\n      # Used above override_conditions_hash_matching to determine if this model adapter will override the\n      # matching behavior for nested subject.\n      # 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","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/CanCanCommunity/cancancan/blob/8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828/lib/cancan/model_adapters/abstract_adapter.rb#L34-L70","documentation":"AbstractAdapter#nested_subject_matches_conditions? (lib/cancan/model_adapters/abstract_adapter.rb:52) raises CanCan::NotImplemented. It is reached only when an adapter declares override_nested_subject_conditions_matching? true without implementing the method, i.e., an incomplete custom adapter handling nested subjects. Nested subject means rules whose conditions hash nests another model's conditions, such as can :read, Comment, project: { owner_id: 1 }.","triggerScenarios":"A custom adapter returning true from override_nested_subject_conditions_matching?(parent, child, conditions) but not implementing nested_subject_matches_conditions?; then a nested-conditions rule like can :read, Comment, project: { owner_id: user.id } is instance-checked with can?(:read, @comment).","commonSituations":"Porting the ActiveRecord adapter to another ORM and missing the nested-subject branch; upgrading cancancan versions where the nested-subject contract changed and the vendored adapter was not updated.","solutions":["Implement self.nested_subject_matches_conditions?(parent, child, all_conditions) in the adapter.","Or return false from override_nested_subject_conditions_matching? to use the default matching path.","As a user of a broken third-party adapter: flatten nested conditions (put the foreign key directly on the model: can :read, Comment, owner_id: user.id) to avoid the nested-subject code path.","Update or patch the adapter gem to the version matching your cancancan release."],"exampleFix":"# before (ability with nested conditions + incomplete adapter)\ncan :read, Comment, project: { owner_id: user.id }\n# can?(:read, @comment) -> CanCan::NotImplemented on adapters claiming the override\n\n# after (flatten the condition onto the model itself)\ncan :read, Comment, project_id: Project.where(owner_id: user.id).pluck(:id)\n# or simply:\ncan :read, Comment, owner_id: user.id   # if the association lives on Comment","handlingStrategy":"validation","validationCode":"# avoid nested-subject conditions when the adapter cannot handle them\ncan :read, Comment, owner_id: user.id         # flat: skips nested-subject matching\ncan :read, Comment, project_id: user.project_ids # flat FK instead of nested hash","typeGuard":"def adapter_supports_nested?(adapter, parent, child)\n  !adapter.override_nested_subject_conditions_matching?(parent, child, {}) || adapter.method(:nested_subject_matches_conditions?).owner != CanCan::ModelAdapters::AbstractAdapter\nend","tryCatchPattern":"begin\n  can?(:read, @comment)\nrescue CanCan::NotImplemented => e\n  Rails.logger.error(\"adapter incomplete: #{e.message}\")\n  false\nend","preventionTips":["Flatten nested conditions to foreign-key conditions on the model itself for unsupported ORMs.","Keep the adapter's nested-subject specs in sync when upgrading cancancan (the contract changes across versions).","Only declare override_nested_subject_conditions_matching? true once nested_subject_matches_conditions? exists."],"tags":["model-adapter","nested-conditions","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"}