【发布时间】:2019-02-12 04:07:01
【问题描述】:
我试图描述一组软件服务共享相似依赖项但并非所有服务都在给定依赖项的相同版本上的想法。
考虑以下模型:
class Service < ApplicationRecord
has_many :service_dependencies
has_many :dependencies, through: :service_dependencies
end
class ServiceDependency < ApplicationRecord
belongs_to :service
belongs_to :dependency
end
class Dependency < ApplicationRecord
has_many :service_dependencies
has_many :services, through: :service_dependencies
has_many :versions, foreign_key: 'dependency_id', class_name: 'DependencyVersion'
end
class DependencyVersion < ApplicationRecord
belongs_to :dependency
end
虽然一个service 可以有多个dependencies,而一个给定的依赖关系可以有多个versions,但任何服务一次只使用一个版本的依赖关系。
如何表达这种关系,以便确定服务当前使用的依赖项的版本?
我认为我可以将当前版本存储在 service_dependencies 表中,但感觉是错误的解决方案。
谢谢
【问题讨论】:
标签: ruby-on-rails activerecord has-many-through