I have an issue where I have a parent model Foo
, which both has_many :bars
and has_many :bazes
. Finally, I also have a join model BarBaz
which belongs_to :bar
and belongs_to :baz
. I want to validate all bar_bazes so that its bar and baz both belong to the same foo. But I can't seem to figure out a way to define a factory for this model that would be valid.
Factory.define(:bar) do |bar|
bar.association(:foo)
end
Factory.define(:baz) do |baz|
bar.association(:foo)
end
Factory.define(:bar_baz) do |bar_baz|
baz_bar.association(:foo)
baz_bar.association(:bar)
baz_bar.association(:baz)
end
I get an invalid record error when I try to create the latter, because the bar and baz factory_girl tries to associate it each have their own foo. Am I screwed?