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

fix: keep the fields order same as the source #49

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/modules/PrismaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class PrismaModel {
if (!model.name) return this;
const field = new PrismaRelationalField(fieldName, model.name);
handleRelationalOptions(field, options);
this.fields.set(fieldName, field);
setImmediate(() => this.fields.set(fieldName, field));
return this;
}

Expand All @@ -170,7 +170,7 @@ export class PrismaModel {
) {
const field = new PrismaEnumField(fieldName, type);
handleEnumOptions(field, options);
this.fields.set(fieldName, field);
setImmediate(() => this.fields.set(fieldName, field));
return this;
}

Expand All @@ -181,7 +181,7 @@ export class PrismaModel {
) {
const field = new PrismaScalarField(fieldName, type);
handleScalarOptions(field, options);
this.fields.set(fieldName, field);
setImmediate(() => this.fields.set(fieldName, field));
return this;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ enum UserStatus {
}

model Post {
content String
deleted Boolean
id String @default(uuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content String
deleted Boolean
}

model User {
status UserStatus
posts Post[]
id String @default(uuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
status UserStatus
posts Post[]
}
"
`;
22 changes: 0 additions & 22 deletions tests/modules/__snapshots__/PrismaModel.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,6 @@ exports[`PrismaModel > Should support adding fields 1`] = `
}"
`;

exports[`PrismaModel > Should support adding mixins > model User {
email String
phoneNumber String
id String @default(uuid()) @id
} 1`] = `
"model User {
email String
phoneNumber String
id String @default(uuid()) @id
}"
`;

exports[`PrismaModel > Should support adding mixins > model User {
email String
phoneNumber String
} 1`] = `
"model User {
email String
phoneNumber String
}"
`;

exports[`PrismaModel > Should support adding mixins > model User {
id String @default(uuid()) @id
email String
Expand Down