我在尝试为我在项目中定义的一些对象和关联创建工厂时遇到了麻烦。我有一种循环类型的关联,其中一个对象与其他两个随后连接在一起的对象关联。
+--------------+ +-------------+
| | | |
| TestCase +---------> | TestDataGrid|
| | | |
+------+-------+ +------+------+
| |
| |
| |
v v
+--------------+ +--------------+
| | | |
| | | |
| TestVariable | | TestDataSet |
| | | |
+------+-------+ +------+-------+
| |
| |
| |
| |
| +---------------+ |
| | | |
| | | |
+---> | TestDataValue |<---+
| |
+---------------+
class TestCase < ActiveRecord::Base
has_many :test_variables, dependent: :destroy
has_many :test_data_grids
#...omitted code...
end
class TestVariable < ActiveRecord::Base
belongs_to :test_case
has_many :test_data_values
#...omitted code...
end
class TestDataValue < ActiveRecord::Base
belongs_to :test_variable
belongs_to :test_data_set
#...omitted code...
end
class TestDataSet < ActiveRecord::Base
belongs_to :test_data_grid
has_many :test_data_values
#...omitted code...
end
class TestDataGrid < ActiveRecord::Base
belongs_to :test_case
has_many :test_data_sets
#...omitted code...
end
基本上,该关联在 TestCase 中分裂并在 TestDataValue 中再次加入,我如何创建一个使用相同对象打开和关闭圆圈的工厂?