Ruby on rails Rails嵌套了许多附加上下文
我试图描述一组软件服务共享相似的依赖关系,但并非所有服务都在给定依赖关系的同一版本上 考虑以下模型:Ruby on rails Rails嵌套了许多附加上下文,ruby-on-rails,activerecord,has-many-through,Ruby On Rails,Activerecord,Has Many Through,我试图描述一组软件服务共享相似的依赖关系,但并非所有服务都在给定依赖关系的同一版本上 考虑以下模型: class Service < ApplicationRecord has_many :service_dependencies has_many :dependencies, through: :service_dependencies end class ServiceDependency < ApplicationRecord belongs_to :servic
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\u dependencies
表中,但这似乎是错误的解决方案
谢谢我想我应该添加一些类似
class Configuration < AR
belongs_to :service
belongs_to :dependency
belongs_to :dependency_version
end
类配置
是的,你会复制信息,但这似乎是有意义的。可能性的实例