Home

Awesome

Build Status

Multitenant

When building multitenant applications, never let an unscoped Model.all accidentally leak data to an unintended audience.

Usage

class User < ActiveRecord::Base
  belongs_to :tenant
  belongs_to_multitenant
  
  validates :email, uniqueness: true                    # application-wide uniqueness
  validates :alias, uniqueness: { scope: :tenant_id }   # tenant-wide uniqueness
end

Multitenant.with_tenant current_tenant do
  # queries within this block are automatically
  # scoped to the current tenant
  User.all

  # new objects created within this block are automatically
  # assigned to the current tenant
  User.create :name => 'Bob'
end

Features

Contributing

Credits

Thanks to Lars Klevan for inspiring this project.

Copyright

Copyright (c) 2011 Ryan Sonnek. See LICENSE.txt for further details.