Replies: 1 comment 3 replies
-
Does using factory as field work for this use case? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
There are some limitations, and potentially unnecessary boilerplate, when setting default values on child models.
Given the models:
We can already override the child values with
.build(...)
:For a PersonFactory to set a default country on their address,
Use(...)
is used in tests and the docs:The first limitation here is that this prevents you from specifying values through the
.build
call:The workaround here is to use
PostGenerated
, example included for other people's benefit:This seems like a fair amount of boilerplate just to be able to set default values (or potentially more constrainted Fakers) on a child factory.
What could be done to simplify this usecase?
Perhaps something like this?:
Beta Was this translation helpful? Give feedback.
All reactions