{"record":{"id":"f1d5100ee8c967fd","repo":"CanCanCommunity/cancancan","slug":"this-model-adapter-does-not-support-fetching-recor","errorCode":null,"errorMessage":"This model adapter does not support fetching records from the database.","messagePattern":"This model adapter does not support fetching records from the database\\.","errorType":"exception","errorClass":"CanCan::NotImplemented","httpStatus":null,"severity":"error","filePath":"lib/cancan/model_adapters/abstract_adapter.rb","lineNumber":73,"sourceCode":"      # 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":55,"sourceCodeEnd":78,"githubUrl":"https://github.com/CanCanCommunity/cancancan/blob/8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828/lib/cancan/model_adapters/abstract_adapter.rb#L55-L78","documentation":"AbstractAdapter#database_records (lib/cancan/model_adapters/abstract_adapter.rb:73) raises CanCan::NotImplemented. AbstractAdapter.adapter_class falls back to the abstract class when no ORM-specific adapter is registered (the gem ships only ActiveRecord 4/5 adapters plus a default), so calling accessible_by on a model whose ORM has no adapter — Sequel, DataMapper, ROM, plain Ruby objects — fails here.","triggerScenarios":"Invoice.accessible_by(current_ability) where Invoice is a Sequel::Model; an index action of load_and_authorize_resource on a non-ActiveRecord model; ActiveRecord not yet loaded/required when accessible_by runs (adapter never registers).","commonSituations":"Introducing CanCanCan into a service object / non-Rails context; a legacy app transitioning between ORMs; gems loading cancancan before the ORM adapter gets required in the boot order.","solutions":["Use ActiveRecord (or a model backed by a supported adapter) for resources you load with accessible_by.","Write a custom adapter: subclass CanCan::ModelAdapters::AbstractAdapter, implement self.for? and database_records, and register it.","Load records manually in the controller and authorize each in Ruby: @records = Invoice.all.select { |i| can?(:read, i) }.","Check require order so the ActiveRecord adapter is loaded before any accessible_by call in initializers."],"exampleFix":"# before\nclass InvoicesController < ApplicationController\n  load_and_authorize_resource  # Invoice is a Sequel::Model -> index raises NotImplemented\nend\n\n# after\nclass InvoicesController < ApplicationController\n  def index\n    @invoices = Invoice.all.select { |i| can?(:read, i) }\n  end\nend","handlingStrategy":"validation","validationCode":"# confirm a real ORM adapter is registered before querying\nadapter = CanCan::ModelAdapters::AbstractAdapter.adapter_class(Invoice)\nraise CanCan::NotImplemented, 'no adapter for this ORM' if adapter == CanCan::ModelAdapters::AbstractAdapter","typeGuard":"def query_supported?(model_class)\n  CanCan::ModelAdapters::AbstractAdapter.adapter_class(model_class) != CanCan::ModelAdapters::AbstractAdapter\nend","tryCatchPattern":"begin\n  @invoices = Invoice.accessible_by(current_ability)\nrescue CanCan::NotImplemented\n  @invoices = Invoice.all.select { |i| can?(:read, i) } # Ruby-side fallback\nend","preventionTips":["Load abilities only for ORMs with a registered adapter (ActiveRecord out of the box).","For non-AR models, authorize per-record with can? instead of accessible_by.","If you maintain an ORM adapter, register it via def self.for? and implement database_records.","Ensure requires ordering: the ORM adapter must load before any accessible_by call in initializers."],"tags":["model-adapter","orm","accessible-by","not-implemented","cancancan"],"backgroundTag":"unsupported-orm-adapter","analyzedSha":"8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828","analyzedAt":"2026-08-21T20:05:55.000Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}