Skip to content
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

Helper to define has-one / has-many relation fields #43

Closed
Tracked by #5
Quramy opened this issue Nov 25, 2022 · 0 comments · Fixed by #45
Closed
Tracked by #5

Helper to define has-one / has-many relation fields #43

Quramy opened this issue Nov 25, 2022 · 0 comments · Fixed by #45
Labels
enhancement New feature or request

Comments

@Quramy
Copy link
Owner

Quramy commented Nov 25, 2022

Something like this:

UserFactory.create({
  posts: {
    create: [await PostFactory.buildCreateInput()]
  }
})

tsc never emits diagnostics for the above code , but the runtime error occurs because the object resolved by buildCreateInput includes { author: { ... } } property.

Solution

Model Factory 's .create() methods screens the input data before passing to Prisma client's raw .crate function.
The screening procedure should the following:

expect(screen({
  id: "",
  name: "",
  posts: {
    create: [{ id: "", author: { ... } }],
    connect: [{ id: "" }],
  }
}).toEqual({
  id: "",
  name: "",
  posts: {
    create: [{ id: "" }], // The author property is removed
    connect: [[ id: "" }],
  }
})
@Quramy Quramy mentioned this issue Nov 25, 2022
16 tasks
@Quramy Quramy added the enhancement New feature or request label Nov 25, 2022
@Quramy Quramy closed this as completed Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant