Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created August 4, 2010 04:01
Show Gist options
  • Save mitchellh/507613 to your computer and use it in GitHub Desktop.
Save mitchellh/507613 to your computer and use it in GitHub Desktop.
# How to properly handle circular references with factory_girl and rails
class Computer < ActiveRecord::Base
has_many :softwares
end
class Software < ActiveRecord::Base
belongs_to :computer
end
Factory.define :computer do |c|
c.softwares do |computer|
5.times.map { computer.association(:software, :computer => nil) }
end
end
Factory.define :software do |s|
s.association :computer
s.name "XMonad"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment