Created
January 12, 2010 10:03
-
-
Save h-lame/275076 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
# Assuming AR test models are present... | |
# The salient bits are: | |
# | |
# class Developer < ActiveRecord::Base | |
# has_many :audit_logs | |
# end | |
# | |
# class AuditLog < ActiveRecord::Base | |
# belongs_to :developer, :validate => true | |
# end | |
d = Developer.new :name => 'Murray' | |
d.audit_logs.build :message => 'What AR does' | |
d.audit_logs.first.developer #=> nil | |
d.valid? #=> true | |
d2 = Developer.new :name => 'Hans' | |
d2.audit_logs.build :message => 'Simulating what :inverse_of does', :developer => d2 | |
d2.audit_logs.first.developer #=> d2 | |
d2.valid? #=> BOOM! Stack Trace Too Deep | |
# It's even worse in reality as the Developer model has a :before_create that | |
# will populate audit_logs with the first AuditLog instance. You can't create or | |
# save any Developer instances! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment