Skip to content

Commit

Permalink
fixed bug described in #76
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishoermann committed Mar 6, 2023
1 parent 8361f45 commit 76692a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/generator/src/classes/extendedDMMF.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DMMF, Dictionary } from '@prisma/generator-helper';

import { GeneratorConfig, configSchema } from '../schemas';
import { ExtendedDMMFDatamodel } from './extendedDMMFDatamodel';
import { ExtendedDMMFMappings } from './extendedDMMFMappings';
import { ExtendedDMMFSchema } from './extendedDMMFSchema';
import { GeneratorConfig, configSchema } from '../schemas';

/////////////////////////////////////////////////
// CLASS
Expand Down
6 changes: 5 additions & 1 deletion packages/generator/src/classes/extendedDMMFInputType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
} from '../constants/regex';
import { GeneratorConfig } from '../schemas';

const SPLIT_NAME_REGEX =
/Unchecked|Create|Update|CreateMany|UpdateMany|Upsert|Where|WhereUnique|OrderBy|ScalarWhere|Aggregate|GroupBy/g;

/////////////////////////////////////////////////
// CLASS
/////////////////////////////////////////////////
Expand Down Expand Up @@ -62,7 +65,8 @@ export class ExtendedDMMFInputType
*/
private _setLinkedModel(datamodel: ExtendedDMMFDatamodel) {
return datamodel.models.find((model) => {
return this.name.match(model.name);
// need to split string to obtain the model name from the input type name.
return model.name === this.name.split(SPLIT_NAME_REGEX)[0];
});
}

Expand Down
27 changes: 25 additions & 2 deletions packages/usage/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ datasource db {
// -----------------------------------------------

generator zod {
// provider = "ts-node-dev ../generator/src/bin.ts"
provider = "zod-prisma-types"
provider = "ts-node-dev ../generator/src/bin.ts"
// provider = "zod-prisma-types"
output = "./generated/zod" // default is ./generated/zod
useMultipleFiles = true // default is false
// createInputTypes = false // default is true
Expand Down Expand Up @@ -238,6 +238,27 @@ model StringRegexModel {
stringThree String /// @zod.string.regex(/^d+s*d+$/)
}

// WRONG MODEL LINKED TO INPUT TYPES
// -----------------------------------------------

// This model covers the following case:
// input type: "UserUncheckedCreateWithoutPractice" should match model "User"
// but matches model "Practice" because practice comes first in the models array.

model Practice {
id Int @id @unique() @default(autoincrement())
profilePhoto Int?
user UserTwo[]
}

model UserTwo {
id Int @id @unique() @default(autoincrement())
name String?
profilePhoto String? @db.Text
practiceId Int?
practice Practice? @relation(fields: [practiceId], references: [id])
}

// model Post {
// id String @id @default(auto()) @map("_id") @db.ObjectId
// title String @default("")
Expand Down Expand Up @@ -290,3 +311,5 @@ model StringRegexModel {
// date DateTime @unique @db.Date
// count Int
// }

//

0 comments on commit 76692a3

Please sign in to comment.