Created
August 4, 2010 04:01
-
-
Save mitchellh/507613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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