ruby on rails - factory_girl: has many through association -
i have rich many many relationship between projects , users. project model has:
has_many :project_members, dependent: :destroy, foreign_key: 'gallery_id' has_many :members, through: :project_members, class_name: 'user', foreign_key: 'member_id'
user model:
has_many :project_members, dependent: :destroy, foreign_key: 'member_id' has_many :member_projects, through: :project_members, source: :member_project
and project_member model:
belongs_to :member_project, foreign_key: 'gallery_id', class_name: 'project' belongs_to :member, foreign_key: 'member_id', class_name: 'user'
i wrote project factory as:
factorygirl.define factory :project_member association :project association :user role 'owner' end end
however gives me:
> undefined method `project=' #<projectmember:0x00000006f66048>
if write following:
factorygirl.define factory :project_member association :member_project, foreign_key: 'gallery_id', class_name: 'project' association :member, foreign_key: 'member_id', class_name: 'user' role 'owner' end end
it says:
factory not registered: member_project
i not sure how define many many through factory object.
assuming have factories project , user
factory :project_member member_project factorygirl.build(:project) member factorygirl.build(:user) role 'owner' end
Comments
Post a Comment