Permalink
Browse files

[ci skip] explain association behavior.

When you manually specify `id:` attribute in a fixture Rails' built in association assignment feature will no longer work. http://stackoverflow.com/questions/23985675/incorrect-association-in-fixtures

This commit raises awareness of this behavior and encourages developers to look directly at the fixture documentation.
  • Loading branch information...
1 parent a93f385 commit 071373857dddeefcb7a36f8838c03c5e88dd6e20 @schneems schneems committed Jun 2, 2014
Showing with 6 additions and 0 deletions.
  1. +6 −0 guides/source/testing.md
View
@@ -96,6 +96,12 @@ one:
category: about
```
+Note: For associations to reference one another by name, you cannot specify the `id:`
+ attribute on the fixtures. Rails will auto assign a primary key to be consistent between
+ runs. If you manually specify an `id:` attribute, this behavior will not work. For more
+ information on this assocation behavior please read the
+ [fixture api documentation](http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html).
+
#### ERB'in It Up
ERB allows you to embed Ruby code within templates. The YAML fixture format is pre-processed with ERB when Rails loads fixtures. This allows you to use Ruby to help you generate some sample data. For example, the following code generates a thousand users:

0 comments on commit 0713738

Please sign in to comment.