To create a one-to-many relationship you could so something like this:
factory :room do
factory :bathroom do
type :bathroom
end
factory :bedroom do
type :bedroom
end
end
factory :house do
ignore do
num_bathrooms 0
num_bedrooms 0
end
trait :two_bathrooms do
num_bathrooms 2
end
trait :three_bedrooms do
num_bedrooms 3
end
after(:create) do |house, evaluator|
create_list(:bathroom, evaluator.num_bathrooms, house: house)
create_list(:bedroom, evaluator.num_bedrooms, house: house)
end
end
Check out the last example in the associations section of this link for more details.