Sha256: d6fb4f411de98fd8cfa1fa2ce55d56789730adcad88de03fff75b100db048b61

Contents?: true

Size: 384 Bytes

Versions: 4

Compression:

Stored size: 384 Bytes

Contents

class ActiveRecord::Base
  class << self
    alias :unscoped_orig :unscoped
    def unscoped
      scope = if respond_to?(:scoped_by_tenant?) && MultiTenant.current_tenant_id
        unscoped_orig.where(arel_table[self.partition_key].eq(MultiTenant.current_tenant_id))
      else
        unscoped_orig
      end

      block_given? ? scope.scoping { yield } : scope
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-multi-tenant-0.4.0 lib/activerecord-multi-tenant/default_scope.rb
activerecord-multi-tenant-0.3.4 lib/activerecord-multi-tenant/default_scope.rb
activerecord-multi-tenant-0.3.3 lib/activerecord-multi-tenant/default_scope.rb
activerecord-multi-tenant-0.3.2 lib/activerecord-multi-tenant/default_scope.rb