Ruby 个 Rails 个协会 - 产品提供和消费服务

Ruby on Rails associations - products provide and consume services

我在 rails 上对 ruby 比较陌生,我需要一些帮助来模拟以下场景:

联想的最佳用途是什么能够得到:

问题与这个问题类似Many-to-many Users and groups, but groups have owners(拥有所有者的用户和组)。但我的产品不一定是所提供服务的消费者。

如有任何帮助,我们将不胜感激!

类似的内容可能适合您

Service belongs_to :provider, class_name: "Product" # services has provider_id
Product has_many :provided_services, class_name: "Service", foreign_key: :provider_id

Product has_many :products_consumed_services
Product has_many :consumed_services, through: :products_consumed_services
ProductsConsumedService belongs_to :product
ProductsConsumedService belongs_to :consumed_service, class_name: "Service"

Service has_many :products_consumed_services, foreign_key: :consumed_service_id
Service has_many :consumers, through: :products_consumed_services, source: :product

提供的服务(来自产品)

product.provided_services

消费服务(来自产品)

product.consumed_services

服务的消费者(来自服务)

service.consumers

提供产品(来自服务)

service.provider