has_many/through
Factory Girl を使って関係を築くのに苦労しています。
私は次のモデルを持っています:
class Job < ActiveRecord::Base
has_many :job_details, :dependent => :destroy
has_many :details, :through => :job_details
end
class Detail < ActiveRecord::Base
has_many :job_details, :dependent => :destroy
has_many :jobs, :through => :job_details
end
class JobDetail < ActiveRecord::Base
attr_accessible :job_id, :detail_id
belongs_to :job
belongs_to :detail
end
私の工場:
factory :job do
association :tenant
title { Faker::Company.catch_phrase }
company { Faker::Company.name }
company_url { Faker::Internet.domain_name }
purchaser_email { Faker::Internet.email }
description { Faker::Lorem.paragraphs(3) }
how_to_apply { Faker::Lorem.sentence }
location "New York, NY"
end
factory :detail do
association :detail_type <--another Factory not show here
description "Full Time"
end
factory :job_detail do
association :job
association :detail
end
私が望むのは、ジョブ ファクトリをデフォルトDetail
の「フルタイム」で作成することです。
私はこれに従おうとしてきましたが、運がありませんでした: FactoryGirl Has Many through
after_create
JobDetail を介して Detail をアタッチするために をどのように使用すべきかわかりません。