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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory doesn't return a db object #162

Open
adrijere opened this issue Jul 6, 2023 · 0 comments
Open

Factory doesn't return a db object #162

adrijere opened this issue Jul 6, 2023 · 0 comments

Comments

@adrijere
Copy link

adrijere commented Jul 6, 2023

Hi 馃憢
First of all, thank you very much for your work. After your answer, we decided to use your lib on our on production application and it saved us a lot of time!

Describe the bug
As mentioned in the documentation, I create a UserProfile which has a relation with the table User. When I use the factory to create a UserProfile, the return object is not similar to one from the DB so I can't call my relation like userProfile.user.

To Reproduce
Create a relation like this:

export const UserProfileFactory = defineUserProfileFactory({
  defaultData: () => ({
    id: chance.guid(), // chance is a lib similar to faker
    firstName: chance.first(),
    user: UserFactory,
  }),
});

In my test, I do : const recipientProfile = await UserProfileFactory.create();.
My recipientProfile doesn't have a user property but a userId which means if I want to do recipientProfile.user I can't and I have to do a prisma call to get my User db object.

Expected behavior
My factory returns a DB object and so I can easily use my relation through my new created object.

Your Schema

model User {
  id                  String              @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
  createdAt           DateTime            @default(now())
  updatedAt           DateTime            @default(now()) @updatedAt
  email               String              @unique
  userProfiles        UserProfile[]
  }

model UserProfile {
  id                  String       @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
  createdAt           DateTime     @default(now())
  updatedAt           DateTime     @default(now()) @updatedAt
  userId              String       @db.Uuid
  user                User         @relation(fields: [userId], references: [id])
  firstName           String?
}

Environment (please complete the following information):

  • Database kind: PostgreSQL
  • Node.js version: 18.14.6
  • @prisma/client version: 4.13.0
  • TypeScript version: 5.0.4

Thanks again for your hard work!

@Quramy Quramy added enhancement New feature or request and removed enhancement New feature or request labels Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants