Projemde tanımladığım bazı nesneler ve ilişkilendirmeler için fabrika oluşturmaya çalışırken sorun yaşıyorum. Bir nesnenin daha sonra bir araya geldiği iki nesne ile ilişkilendirildiği döngüsel bir ilişki var.FactoryGirl'de döngüsel bir ilişki için fabrikaları nasıl oluşturabilirim?
+--------------+ +-------------+
| | | |
| 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
I açılır ve aynı nesneler ile daire kapatan bir fabrika oluşturmak nasıl Temel olarak, ilişkilendirme TestCase böler ve TestDataValue tekrar birleştirilmektedir? Bu test edilmemiştir
Gerçekten buna ihtiyacınız var mı? Vakaların çoğunda tüm bu ilişkilerle dalga geçebilir ve saplayabilirsin. Bu karmaşık fabrikaları korumak son derece zordur. – Sigurd