-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Relations are throwing error when you use include #324
- Loading branch information
Seven Du
committed
Jan 18, 2024
1 parent
9e2349a
commit b0862e7
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# Install Node.js | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
|
||
# Install Dart SDK | ||
- uses: dart-lang/setup-dart@v1 | ||
with: | ||
sdk: stable | ||
|
||
- name: Install dependencies | ||
run: dart pub get && npm install | ||
|
||
- name: Generate test client & create test db | ||
run: npx prisma db push --schema test/schema.prisma --accept-data-loss --force-reset | ||
|
||
- name: Analyze | ||
run: dart analyze | ||
- name: Test | ||
run: dart test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
generated/ | ||
test.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:orm/orm.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'generated/client.dart'; | ||
import 'generated/prisma.dart'; | ||
|
||
void main() { | ||
late PrismaClient client; | ||
|
||
setUpAll(() async { | ||
client = PrismaClient(datasourceUrl: 'file:test/test.db'); | ||
await client.$connect(); | ||
|
||
// Clear database | ||
await client.user.deleteMany(); | ||
|
||
// Seed database | ||
await client.user.create( | ||
data: PrismaUnion.$2( | ||
UserUncheckedCreateInput( | ||
name: "Seven", | ||
posts: PostUncheckedCreateNestedManyWithoutAuthorInput( | ||
create: PrismaUnion.$2( | ||
PrismaUnion.$1([ | ||
PostCreateWithoutAuthorInput(title: "First post"), | ||
PostCreateWithoutAuthorInput(title: "Second post"), | ||
]), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
tearDownAll(() async { | ||
await client.$disconnect(); | ||
}); | ||
|
||
test('findMany include list refer', () async { | ||
final users = await client.user.findMany( | ||
include: UserInclude(posts: PrismaUnion.$1(true)), | ||
); | ||
|
||
expect(users.length, 1); | ||
expect(users.first.posts?.length, 2); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
generator client { | ||
provider = "dart run orm" | ||
output = "generated" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./test.db" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
posts Post[] | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
author User @relation(fields: [authorId], references: [id], onDelete: Cascade) | ||
authorId Int | ||
} |
b0862e7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
prisma-dart – ./
prisma-dart-herodeveloper.vercel.app
prisma-dart-git-main-herodeveloper.vercel.app
prisma.pub
prisma-dart.vercel.app
www.prisma.pub