fix(Generator): 🐛 Fix the issue with mapping default values in the generated Prisma classes.#1
Conversation
…d fields incorrectly being assigned to a date object like `new Date('1')` for `Int` fields (if the default value was 1 in this case) or not being assigned at all.
Update the PostgreSQL Prisma schema for testing the default values.
Reformat the changed files.
|
Hi, thanks a lot for your pull request and the participation in this project. I will check the changes in the next days, as this is not a full time project for me. I am rather thinking about what is required to make this generator work with new prisma client! Did you already try this? |
|
Hello, you're welcome. No, I have not tried to make this generator work with the new Prisma Client v7, if that's what you are asking. I plan on using this generator with v6 for now, as we need this fix to be put in before we can utilize this generator for our company's project. |
|
@jannis6023 |
|
@dshk0718 hey, i have not yet been able to look into the PR. I had to finish the prisma v7 migration first. I will push this to a new branch - already deployed on npmjs as 7.0.0! i will check your pr on prisma v6 first and will then migrate it to v7 if there occur any changes. |
|
@jannis6023 |
|
@jannis6023 |
|
Hi, I just merged the pull request and release 0.6.0 to npm. |
|
Hello @jannis6023, |
|
@jannis6023 |
|
@jannis6023 |


This PR is also here: kimjbstar#77
However, given that the original author of the
prisma-class-generatoris completely AFK and a no-show on that repo (this PR has been open on that repo for 2 weeks now; and there are many other open PRs that are not even reviewed), I am attempting to merge this fix to your fork here, since your fork was already published recently as a separateprisma-class-generatorNPM package on the NPM registry.PR Changes Summary
Fix the issue with the default values for the mapped fields incorrectly being assigned to a date object like
new Date('1')forIntfields (if the default value was 1 in this case) or not being assigned at all.Fixes
Inttype in the Prisma schema would get generated asnew Date('1')(in the case the default value was set to1in the Prisma schema for the given field).Inttype with@default(1)kimjbstar/prisma-class-generator#76Proposed Changes
releasedAtto theProductmodel in the PostgreSQL Prisma schema for testing date fields with a fixed date-time value (not using Prisma@default(now())directive or Prisma@updatedAtdirective).undefinedornull, instead of just checking on the truthiness of the default value. Checking only for the truthiness of the default value was causing the default value of0for theInttype fields not to get assigned the default value of0in the generated class.@updatedAtdirective.Here's more detail on what this PR fixes:
@jannis6023
Just to verify it here, this is the output of the generated Prisma class with these fixes on this PR:
As you can see, all the issues that were mentioned in kimjbstar#34, kimjbstar#56, kimjbstar#68, and kimjbstar#76 are fixed with the fixes I am proposing to push.