Coder Social home page Coder Social logo

acts_as_many_tenants's Introduction

Acts As Many Tenants

As an extension for acts_as_tenant this gem allows for a model to belong to many tenants.

acts_as_many_tenants sets up a has_and_belongs_to_many relationship to a tenant model and introduces a default_scope that checks for the existence of an association to ActsAsTenant.current_tenant.

Usage

Add the following line to your model

acts_as_many_tenants

You can specify the name of the tenant model as an attribute (defaults to Account).

acts_as_many_tenants(:accounts)

You can also use a has_many :through relation for tenants. For example a Task may belong to a Project and relate to many accounts through its project:

acts_as_many_tenants(:accounts, :through => :project)

You can provide a class_name (useful when using namespaces):

acts_as_many_tenants(:accounts, :through => :project, :class_name => 'Foo::Project)

Newly created models get the current_tenant assigned if you haven’t assigned any tenants yourself.
Pass :auto => false to prevent this behaviour:

acts_as_many_tenants(:accounts, :auto => false)

Add :required => true in order to validate the presence of an associated tenant.

acts_as_many_tenants(:accounts, :auto => false, :required => true)

Installation

Add the following line to your Gemfile

gem 'acts_as_many_tenants', :git => 'git://github.com/laurens/acts_as_many_tenants.git'

and run

bundle install

TODO

Make associations immutable in order to align with acts_as_tenant. At the moment only the association=[model] and association_ids=ids methods take care of that. Missing implementation for the other association writers associations.<<(model), associations.delete(model), associations.clear, associations.build, associations.create.

Pull Requests welcome!

Author & Credits

acts_as_many_tenants is written by Laurens Nienhaus as an extension for and inspired by acts_as_tenant.

License

Copyright (c) 2013 Laurens Nienhaus, released under the MIT license

acts_as_many_tenants's People

Contributors

laurens avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.