-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for required values typing on build/create, not on define #115
Labels
Comments
KieranP
changed the title
Optional vs Required values
Support for required values typing on build/create, not on define
Apr 5, 2023
The return value of your factory must be a valid const userFactory = Factory.define<User>(({ onCreate }) => {
onCreate(attrs => User.create(attrs));
return {
title: 'Testing',
author_id: '1' // add this line
}
}) Your suggestion of having the factory return only part of the object and |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have a bunch of factories mapped to various DB structures. As is the case for most projects, the DB has some required fields and some optional ones. So we created a Typescript type indicating which were required/optional, and passed them into Fishery.
However, the factory definition can't specify some of these attributes up front (e.g. a post factory might have an author_id which needs to be passed into it). However, the author_id is still required when we create the record. But fishery doesn't seem to support this case.
e.g.
We are providing the title for the post, but the author_id needs to be passed in on create.
However, the Factory typing barfs and as a result, the create call also complains.
It would be great if fishery types could accept any attributes when defining the factory, and only check typing on build/create
In the meantime, to get everything working, I have to make all values optional:
but this obviously leads to issues where required attributes are missed
The text was updated successfully, but these errors were encountered: