I'm trying to have a factory build an
Offering object with a child object
Rating that will receive the
item_id from it's parent.
FactoryGirl.define do factory :offering do item_id nil element_id nil association :rating, factory: :rating, strategy: :build, :item => item_id end end
The Offering is created with
offering = FactoryGirl.create :offering, item_id: 21, element_id: 211
But when run, it aborts with an error
Failure/Error: offering = FactoryGirl.create :offering, item_id: 21, element_id: 211 ArgumentError: Trait not registered: item_id
I assume the error occurs because the
item_id in the association definition is not "lazy" and therefor undefined.
How can I solve this?