Re: #431 -- Added a note about `strategy: :build`

This commit is contained in:
Hosam Aly 2012-09-07 17:47:39 +02:00 committed by Joshua Clayton
parent 71c13363a3
commit fd56f884e4
1 changed files with 9 additions and 0 deletions

View File

@ -336,6 +336,15 @@ post.new_record? # => true
post.author.new_record? # => true
```
Please note that the `strategy: :build` option must be passed to an explicit call to `association`,
and cannot be used with implicit associations:
```ruby
factory :post do
# ...
author strategy: :build # <<< this does *not* work; causes author_id to be nil
```
Generating data for a `has_many` relationship is a bit more involved,
depending on the amount of flexibility desired, but here's a surefire example
of generating associated data.