Hi,
I have two factories. The first's model contains a has_many
relationship to the second's model. I want the first factory to build
an instance of the second when accessed. So I tried this:
# ContactRole has_many :contexts
Factory.define :contact_role do |r|
r.name 'Primary Contact'
r.description 'Test Role'
r.contexts do |contexts|
[contexts.association(:contact_role_context)]
end
end
# ContactRoleContext belongs_to :role
Factory.define :contact_role_context do |c|
c.association :role, :factory => :contact_role
c.add_attribute :context, 'Place'
end
When I execute Factory.build(:contact_role) I get a stack overflow,
presumably because of the circular dependency here. Is there a way to
set this up so that it works?