Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails嵌套了许多附加上下文_Ruby On Rails_Activerecord_Has Many Through - Fatal编程技术网

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
类配置
是的,你会复制信息,但这似乎是有意义的。可能性的实例