Ruby on rails 多租户以及在租户上下文中使用ruby委托与NoSQL
我有一个多租户应用程序(rails后端),我需要将租户无关的预填充项目列表与特定于租户的属性混合在一起 我想知道是否有人使用委托完成了这项工作,并且与从Postgres冒险进入MongoDB相比表现良好 示例模型:Ruby on rails 多租户以及在租户上下文中使用ruby委托与NoSQL,ruby-on-rails,ruby,postgresql,multi-tenant,Ruby On Rails,Ruby,Postgresql,Multi Tenant,我有一个多租户应用程序(rails后端),我需要将租户无关的预填充项目列表与特定于租户的属性混合在一起 我想知道是否有人使用委托完成了这项工作,并且与从Postgres冒险进入MongoDB相比表现良好 示例模型: Class EquipmentList < ActiveRecord::Base attr_accessible :name, :category_id has_one :tenant_equipment_list delegate :alt_name, to:
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
Class设备列表
我已在低流量站点上成功运行了此功能。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
Class设备列表
我已在低流量站点上成功运行了此功能。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
Class设备列表
Update:在低流量站点中执行此操作,迄今为止未发现任何问题。Update:在低流量站点中执行此操作,迄今为止未发现任何问题。