Module: Ec::Pg::RlsMixin
Overview
Mixin for ActiveRecord models that participate in multi-tenancy.
Include via acts_as_rls in your model or add it to ApplicationRecord.
Usage
class ApplicationRecord < ActiveRecord::Base
include Ec::Pg::RlsMixin
acts_as_rls
end
What it does
- Adds an +around_action+-compatible callback that applies RLS before every query on the model when a tenant is active in the thread context.
- Provides a
with_rlsclass method for explicit scoping. - Optionally raises TenantNotSet when required: true and no tenant is set.
Defined Under Namespace
Classes: RlsError
Constant Summary collapse
- RlsModes =
%i(local session)