アソシエーションの構築に問題があります。私は自分のモデルを次のように定義しています:
class Conversation
belongs_to :user1
belongs_to :user2
has_many :messages
end
これらの工場を定義しました
factory :user do
name "name"
end
factory :female, parent: :user do
gender 'f'
end
factory :male, parent: :user do
gender 'm'
end
factory :message do
message "message"
conversation
end
今、私はこのような工場「conversation_with_messages」を作成しようとしています
factory :conversation do
read false
association :user1, factory: :male
association :user2, factory: :female
factory :conversation_with_messages do
ignore do
messages_count 10
end
after(:create) do |conversation, evaluator|
FactoryGirl.create_list(:message, evaluator.messages_count, author: conversation.user1)
end
end
end
しかしFactoryGirl.create(:conversation_with_messages)
、そうすると、user1_id列がnullではない必要があるというデータベースエラーが発生します。
このコラムが記入されていない理由と、ここで何が間違っているのか疑問に思っています。