All threads / Row-level Multitenancy with ActsAsTenant Discussion

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Row-level Multitenancy with ActsAsTenant Discussion

Of all the multi tenancy methods you have used, which one do you think is the best. I know it depends, but I need your opinion, which one would your mind start thinking of?

Reply

If it's not a healthcare app or where it's required that data needs to be separated then row based.

Reply

Honestly I don't even do pure row level tenancy most of the time, just query by top level account, company, etc. I only move to multi-tenant when clients require it or for white-labeled SAAS solutions.

Reply

Relative newbie here developing my first SaaS app and I"m struggling with the data model hierarchy. I'm expecting my customers will have 2-10 Users per Company. Currently I'll be manually onboarding customers, so I could have Users belong to a Company and create each Company and it's Users.
Seems counter to the typical model where User sits at the top, and also could be a problem if I move to self-serve signup down the road(though obviously I could create a dummy company until they fill in the info)
Any advice?

Reply

You can let people sign up using devise but accept a nested attribute for company and get the company name on the signup form as well. Company has many users and user belongs to company. Another thing is having a join table so

Company: has_many company_users
CompanyUser: belongs_to company, belongs_to user
User: has_many :company_users, belongs_to company, through: company_user

Reply

Thanks! To clarify, are you suggesting I create Company and User in the same form? I'm looking at blog posts like this for guidance: https://revs.runtime-revolution.com/saving-multiple-models-with-form-objects-and-transactions-2c26f37f7b9a.

Is that heading in the right direction?

To close this off, I couldn't get the above approach to work, and decided I don't really need it at this point, I can create Users and Companies from my admin dashboard.

I was able to get the model relations working, the only problem I encountered was I couldn't figure out how to bypass acts_as_tenant on my static(marketing) pages, so had to implement for each controller, which will work (just have to remember for new controllers!).

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,406+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.