Module: MultiTenant::ProxiesToTenant::ProxiesToTenantSingularInverseAssociation

Defined in:
lib/multi_tenant/proxies_to_tenant.rb

Overview

Class methods for tenant proxies that have a singular inverse association (i.e. belongs_to or has_one).

Instance Method Summary collapse

Instance Method Details

#current_tenantsObject

Returns the current record of the proxy model



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/multi_tenant/proxies_to_tenant.rb', line 98

def current_tenants
  proxied_tenant_class
    .current_tenants
    .map { |tenant|
      if (proxy = tenant.send(proxied_tenant_inverse_assoc))
        proxy
      else
        tenant_id = tenant.send(proxied_tenant_class.primary_key)
        raise ::MultiTenant::NilProxyError, "Missing proxy for tenant #{proxied_tenant_class.name}##{tenant_id}"
      end
    }
end