Module: Multitenant::ActiveRecordExtensions
- Defined in:
- lib/multitenant.rb
Instance Method Summary collapse
-
#belongs_to_multitenant(association = :tenant) ⇒ Object
configure the current model to automatically query and populate objects based on the current tenant see Multitenant#current_tenant.
Instance Method Details
#belongs_to_multitenant(association = :tenant) ⇒ Object
configure the current model to automatically query and populate objects based on the current tenant see Multitenant#current_tenant
27 28 29 30 31 32 33 34 35 |
# File 'lib/multitenant.rb', line 27 def belongs_to_multitenant(association = :tenant) reflection = reflect_on_association association before_validation Proc.new {|m| m.send("#{association}=".to_sym, Multitenant.current_tenant) if Multitenant.current_tenant }, :on => :create default_scope lambda { where({reflection.foreign_key => Multitenant.current_tenant.id}) if Multitenant.current_tenant } end |