0
我仍然無法找到解決方案來解決使用Sequel時出現的關聯工廠問題。相關對象沒有主鍵
我有依靠one_to_many
兩種型號,這是一樣的has_many
在活動記錄,並many_to_one
,這是相同的Active Record belongs_to
。
這裏是定義工廠:
FactoryGirl.define do
to_create { |instance| instance.save }
factory :post do
title "some title"
end
end
FactoryGirl.define do
to_create { |instance| instance.save }
factory :comment do
content "some content"
association :post, strategy: :build
end
end
當運行build(:comment)
,它失敗:
Associated object does not have a primary key.
有沒有人有一個想法如何解決呢?我總是可以先構建/創建一個帖子,然後簽署一個評論,但這很乏味。更重要的是,我將不得不刪除association :post, strategy: :build
並使用一些Integer隨機值。
我使用:
factory_girl_rails 4.8.0
ruby 2.4.0
sequel-rails 0.9.15
sequel 4.45.0