【问题标题】:multi-tenant and use of ruby delegate vs NoSQL for tenant context多租户以及在租户上下文中使用 ruby​​ 委托与 NoSQL
【发布时间】:2016-04-09 07:20:22
【问题描述】:

我有一个多租户应用程序(rails 后端),我需要将与租户无关的预填充项目列表与租户特定属性混合在一起。

想知道我是否有人使用过委托来完成这项工作,并且与从 Postgres 冒险进入 MongoDB 相比,性能还不错

示例模型:

Class EquipmentList < ActiveRecord::Base
  attr_accessible :name, :category_id

  has_one :tenant_equipment_list

  delegate :alt_name, to: tenant_equipment_list

end

Class TenantEquipmentList < ActiveRecord::Base
  attr_accessible :alt_name, :group, :sku, :est_price, :equipment_list_id

  belongs_to :equipment_list

  default_scope { where(tenant_id: Tenant.current_id) }
end

【问题讨论】:

  • 更新:一直在一个低流量的网站上做这个,到目前为止还没有发现任何问题。

标签: ruby-on-rails ruby postgresql multi-tenant


【解决方案1】:

我已经在一个低流量的网站上成功运行了这个。 rails 后端在输出到 json 时处理得很好。

意识到最好使用租户版本作为外键并将主属性委托给租户。看起来像这样:

Class EquipmentList < ActiveRecord::Base
  attr_accessible :name, :category_id

  has_one :tenant_equipment_list



end

Class TenantEquipmentList < ActiveRecord::Base
  attr_accessible :alt_name, :group, :sku, :est_price, :equipment_list_id

  belongs_to :equipment_list

  delegate :name, to: tenant_equipment_list #prefix: true if you want

  default_scope { where(tenant_id: Tenant.current_id) }
end

【讨论】:

    猜你喜欢
    • 2022-10-25
    • 2018-05-07
    • 2011-08-16
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    相关资源
    最近更新 更多