mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
16 lines
492 B
Ruby
16 lines
492 B
Ruby
# 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 |