Ich habe die folgenden Verbändenfactory Verbindung mit anderen Namen
class Training < ApplicationRecord
has_many :attendances
has_many :attendees, through: :attendances
end
class Attendance < ApplicationRecord
belongs_to :training
belongs_to :attendee, class_name: 'Employee'
Die Anwesenheits Tabelle attendee_id
und training_id
hat.
Nun, wie kann ich eine gültige Attendance
mit FactoryGirl erstellen?
Derzeit habe ich den folgenden 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
Aber ich bekomme
NoMethodError:
undefined method `employee=' for #<Attendance:0x007f83b163b8e8>
Ich habe auch versucht
FactoryGirl.define do
factory :attendance do
training
association :attendee, factory: :employee
end
end
Mit dem gleichen Ergebnis.
Danke für Ihre Hilfe (oder höflich sein ist nicht erlaubt auf SO ???).