I have the following associations
class Training < ApplicationRecord
has_many :attendances
has_many :attendees, through: :attendances
end
class Attendance < ApplicationRecord
belongs_to :training
belongs_to :attendee, class_name: 'Employee'
The Attendance table has attendee_id
and training_id
.
Now, How can I create a valid Attendance
with FactoryGirl?
Currently, I have the following code
FactoryGirl.define do
factory :attendance do
training
attendee
end
end
FactoryGirl.define do
factory :employee, aliases: [:attendee] do
sequence(:full_name) { |n| "John Doe#{n}" }
department
end
end
But I get
NoMethodError:
undefined method `employee=' for #<Attendance:0x007f83b163b8e8>
I have also tried
FactoryGirl.define do
factory :attendance do
training
association :attendee, factory: :employee
end
end
With the same outcome.
Thanks for your help (or being polite is not allowed on SO???).