问题描述
所有数据隔离都由每个表格中的TenantID列完成。
对于所有租户模式,什么是自动处理多租户的最佳方式。
示例:
Contacts.new({.....})应该自动添加:tenant => curret_user.tenant
Contacts.where({....})还应该添加:tenant => curret_user.tenant
目前,我在CanCan gem中看到这样的东西,可以为特定的用户参数提取记录。但是它并没有为插入和更新操作提供任何东西。或者可能我不明白如何做到。
Regards,
Alexey Zakharov。
可以通过租户对象处理所有的集合。
这里是使用Mongoid的示例:
#查找所有价格> 500当前租户范围
current_tenant.products.where(:price.gt => 500)
#它也适用于创建和保存操作
current_tenant.products.create:name => apple,:price => 200
I'm building multi-tenant application.
All data isolation is done by TenantID column in each table.
What is the best way to automatically handle multi-tenancy for all tenant models.
Example:
Contacts.new({.....}) should automatically add :tenant => curret_user.tenant
Contacts.where({....}) should also add :tenant => curret_user.tenant
Currently I see something like this in CanCan gem which that can fetch records for specific user parameters. But it is not providing anything for insert and update operation. Or may be I doesn't understand how to do it.
Regards,Alexey Zakharov.
It is possible if you will work with all collections through tenant object.
Here is sample using Mongoid:
#Find all products with price > 500 in current tenant scope
current_tenant.products.where(:price.gt => 500)
#It also work for create and save operations
current_tenant.products.create :name => "apple", :price => 200
这篇关于在Rails 3中处理多租户的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!