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

How to override what faker.js generates for a specific fields #12

Open
laneme opened this issue Jul 25, 2023 · 7 comments
Open

How to override what faker.js generates for a specific fields #12

laneme opened this issue Jul 25, 2023 · 7 comments

Comments

@laneme
Copy link

laneme commented Jul 25, 2023

Trying to achieve this

  /// FAKE: faker.database.mongodbObjectId()
  user_id          String          @db.ObjectId

It still generates a fake string user_id: faker.lorem.words(5)

I know its already possible to generate cusom JSONs and that works! But this wouldve been a nice addition.

I'm not sure if it already exist.

@luisrudge
Copy link
Owner

Yeah, that's a good idea. I tried to find a way to get the @db.ObjectId info from the model info, but it's not exposed anywhere. Ideally, we'd just detect that and use mongodbObjectId instead. I'll ping someone from the Prisma team to see if it's possible.

@luisrudge
Copy link
Owner

follow up here: prisma/prisma#20385

@laneme
Copy link
Author

laneme commented Jul 25, 2023

That would definitely be the most ideal way of doing it. But i would still be open to the idea of overriding with comments.

I know faker text generation is supposted to save time but some time we might want someth more than just faker.lorem.words(5)

I used some zod schema generators and I have to override them for almost most fields.

/// @zod.custom.use(z.coerce.number().positive({message: "Must be a positive interger"}))

Thanks for the lib btw <3

@mjjjjjjlindow
Copy link

I second the idea of being able to override specific fields with:

/// FAKE: faker.someMethod()

or

/// Fake: someFunction()

This would be especially helpful for optional fields.

@luisrudge
Copy link
Owner

I'd be happy to review and merge a PR with this change!

@mjjjjjjlindow
Copy link

Sounds good! I will see if I can work that in.

@jamespsterling
Copy link

+1 need this as well.

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

4 participants