5

マルチテナントアプリケーションを構築しています。

すべてのデータ分離は、各テーブルの TenantID 列によって行われます。

すべてのテナント モデルのマルチテナンシーを自動的に処理する最善の方法は何ですか。

例:

Contacts.new({.....}) should automatically add :tenant => curret_user.tenant
Contacts.where({....}) should also add :tenant => curret_user.tenant

現在、特定のユーザーパラメーターのレコードを取得できる CanCan gem でこのようなものを見ています。ただし、挿入および更新操作には何も提供していません。あるいはやり方が分からないのかもしれません。

よろしく、アレクセイ・ザハロフ。

4

3 に答える 3

1

テナント オブジェクトを介してすべてのコレクションを操作する場合は可能です。

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
于 2010-09-30T14:40:34.840 に答える
1

マルチテナンシーにはAct As Tenant gemを使用しました。とても使いやすくて良い宝石です。これは、このgem Act As Tenantのドキュメントです

于 2014-12-01T10:31:16.357 に答える
1

マルチテナント Ruby gem をチェックすることをお勧めします。実行されるすべてのクエリが現在のテナントを尊重していることを確認するのは簡単です。 http://blog.codecrate.com/2011/03/multitenant-locking-down-your-app-and.html

元:

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

  # records created within this block are
  # automatically assigned to the current tenant
  User.create :name => 'Bob'
end
于 2011-05-23T13:49:45.190 に答える