mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Re: #431 -- Added a note about strategy: :build
This commit is contained in:
parent
71c13363a3
commit
fd56f884e4
1 changed files with 9 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue