#issue.rb
class Issue < ActiveRecord::Base
has_one :resolve,:dependent => :destroy,:inverse_of => :issue
#resolve.rb
class Resolve < ActiveRecord::Base
belongs_to :issue,:inverse_of => :resolve
end
#Factories.rb
FactoryGirl.define do
factory :issue do
factory :issue_with_resolve do
after(:create) do |issue|
FactoryGirl.create(:resolve,issue: issue)
end
end
end
我发现如果在 model 中不加:inverse_of 那么FactoryGirl.create(:issue_with_resolve).resolve
返回值总是 nil。
不知道大家遇到过这样的问题么?也是通过添加 inverse_of 解决的么?还是我是用 FactoryGril 的方式有问题?