Files
astuto/app/models/concerns/TenantOwnable.rb

16 lines
492 B
Ruby
Raw Normal View History

2022-07-18 10:47:54 +02:00
# A TenantOwnable model belongs to a tenant
# A TenantOwnable model must have a tenant_id column
module TenantOwnable
extend ActiveSupport::Concern
included do
# Tenant is actually not optional, but we not do want
# to generate a SELECT query to verify the tenant is
# there every time. We get this protection for free
# through database FK constraints
belongs_to :tenant, optional: true
default_scope { where(tenant: Current.tenant_or_raise!) }
end
end