Skip to content

Commit 0e49b20

Browse files
authored
Fix #513 -- Add missing doc on _refresh_after_create option (#514)
1 parent aa2ab44 commit 0e49b20

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased](https://github.com/model-bakers/model_bakery/tree/main)
99

1010
### Added
11+
- docs: Add missing doc on `_refresh_after_create` option
1112

1213
### Changed
1314
- Fix `Recipe.prepare` without _quantity (on one-to-one relation)

docs/basic_usage.md

+18
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ Model Bakery does not create files for FileField types. If you need to have the
242242

243243
**Important**: the lib does not do any kind of file clean up, so it's up to you to delete the files created by it.
244244

245+
## Refreshing Instances After Creation
246+
247+
By default, Model Bakery does not refresh the instance after it is created and saved.
248+
If you want to refresh the instance after it is created,
249+
you can pass the flag `_refresh_after_create=True` to either `baker.make` or `baker.make_recipe`.
250+
This ensures that any changes made by the database or signal handlers are reflected in the instance.
251+
252+
```python
253+
from model_bakery import baker
254+
255+
# default behavior
256+
customer = baker.make('shop.Customer', birthday='1990-01-01', _refresh_after_create=False)
257+
assert customer.birthday == '1990-01-01'
258+
259+
customer = baker.make('shop.Customer', birthday='1990-01-01', _refresh_after_create=True)
260+
assert customer.birthday == datetime.date(1990, 1, 1)
261+
```
262+
245263
## Non persistent objects
246264

247265
If you don't need a persisted object, Model Bakery can handle this for you as well with the **prepare** method:

0 commit comments

Comments
 (0)