我有兩個簡單的工廠:如何在FactoryGirl中使用自加入關聯?
factory :parent_category, :class => Category do
name "Garden"
parent_id 0
display_order 1
end
factory :category do
association :parent_id, factory: :parent_category
name "Tools"
associated_categories ""
postfix_to_display ''
display_order 1
end
但是,當我嘗試使用,以產生一個工廠:
f = FactoryGirl.create(:category)
我收到以下錯誤:
NoMethodError: undefined method `to_i' for #<Category:0x007fdf50495c00>
我使用Rails 3.2.12和FactoryGirl 4.2。
我們可以在你的'Category'模型來看看聯想? – depa
您的問題幫助我正確建立了一個帶有內部連接關聯的FactoryGirl。我已經完成了你需要解決你的問題,但不是你已經做了什麼來創建你的問題:) –