ruby on rails - factorygirl create error -


when debugging in console pry,i have run brief = factory(:brief,:project => factory(:project)) command.it supposed work got error.

 activerecord::recordnotunique: pg::error: error:  duplicate key value violates unique constraint "index_briefs_on_project_id"     detail:  key (project_id)=(15389) exists.     : insert "briefs" ("project_id", "duration", "brand_name", "brand_info",  "customer_info", "competitor_info", "desired_impression", "competencies", "preferences",  "examples", "notes", "created_at", "updated_at", "channel_id") values (15389, 14, null,  'brand info', null, null, null, null, null, null, null,  '2013-04-06 01:07:04.717364', '2013-04-06 01:07:04.717364', null) returning "id" 

why error occurs , how can fix ?

edited: added factory files

brief_factory.rb

factory.define :brief, :class => brief |b|   b.brand_info 'brand info'   b.duration 14 end 

project_factory.rb

factory.define :project, :class => project |p|   p.association :owner, :factory => :customer    p.title 'project title'   p.description 'project description'   p.stage :brief_completed   p.contest_type :standard    p.brief factory.build(:brief)   p.association :project_type, :factory => :project_type end 

it looks project factory automatically creating brief. factory(:brief,:project => factory(:project)) attempt create 2 briefs associated same project. second fails because have unique constraint on project_id column in briefs table.

with factories have defined can trying in pry with:

project = factory(:project) brief = project.brief 

or just:

brief = factory(:project).brief 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -