Josef Henryson
10/05/2022, 12:21 PMDibas Dauliya
10/05/2022, 12:50 PMpost
column with relation to postID
. I gave postID
and assumed it will automatically fill post
but I gave me error asking for post
. How can I include post in it?Evangelos Charalampidis
10/05/2022, 1:02 PMmodel User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String?
age Int?
bio String?
location String?
tasks Task[]
comments Comment[]
}
model Task {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String?
description String?
progress ProgressStatus @default(ToDo)
taskType TaskType @default(Personal)
comments Comment[]
User User? @relation(fields: [userId], references: [id])
userId Int?
}
enum ProgressStatus {
ToDo
InProgress
Blocked
Completed
}
enum TaskType {
Personal
Coding
Bruno
House
}
model Comment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
desc String
likes Int?
dislikes Int?
Task Task? @relation(fields: [taskId], references: [id])
taskId Int?
User User? @relation(fields: [userId], references: [id])
userId Int?
}
that’s how I create three users
const users = await prisma.user.createMany({
data: [
{
username: "imevanc",
age: 25,
bio: "I love maths",
location: "Earth",
},
{
username: "imevancc",
age: 30,
bio: "I love physics",
location: "Mars",
},
{
username: "imevanc",
age: 35,
bio: "I love biology",
location: "Jupiter",
},
],
});
and here I’m trying to associate the first task that I create with the first user. however, both tasks are linked to the first user for some reason.
const task = await prisma.task.createMany({
data: [
{
title: "Bruno's morning walk",
description:
"I need to take Bruno to the park and walk him for just over an hour.",
progress: "Completed",
taskType: "Bruno",
userId: 1,
},
{
title: "Bruno's evening walk",
description: "I need to walk Bruno in the city center.",
progress: "ToDo",
taskType: "Bruno",
},
],
Any help would be appreciated! Cheers!
});
Marvin
10/05/2022, 2:19 PMmodel User {
id String @id @default(cuid())
friends FriendOnUser[]
}
model FriendOnUser {
id String @id @default(cuid())
addedAt DateTime @default(now())
parentId String?
parent User @relation(name: "ParentUser", fields: [parentId], references: [id])
friendId String?
friend User @relation(name: "FriendUser", fields: [parentId], references: [id])
}
Florian
10/05/2022, 2:42 PMprisma.modelOne.create({
data: {
id: '1',
field: 'string',
modelTwo: {
connect: {
id: someID,
},
},
},
});
over
prisma.modelOne.create({
data: {
id: '1',
field: 'string',
modelTwoID: someID,
},
});
or if both methods are the same?
schema.prisma
would look something like this:
model ModelOne {
id String @id
field String
modelTwo ModelTwo @relation(name: "ModelsRelation", fields: [modelTwoID], references: [id], onDelete: Cascade)
modelTwoID String
}
model ModelTwo {
id String @id
field String
modelOnes ModelOne[] @relation(name: "ModelsRelation")
}
Joey
10/05/2022, 2:45 PMModelNameUpdateInput
, but I can’t figure out how to import that, anyone know?Vivek Poddar
10/05/2022, 3:49 PMcreatedAt
, updatedAt
, createdBy
, updatedBy
fields, but I am getting issues when I there is already an existing relationship with User
.
For example
model Order {
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
...
createdBy User?
}
I get the following error:
Error validating model "Partner": Ambiguous relation detected. The fields `user` and `createdBy` in model `Partner` both refer to `User`. Please provide different relation names for them by adding `@relation(<name>).
1. How can I resolves this issue?
2. Is there any better pattern?Peter
10/05/2022, 6:28 PMprisma generate
in production?John Allen Delos Reyes
10/06/2022, 3:29 AMtype
in data.type for type assetUncheckedCreateInput. Did you mean typeId
? Available args: type assetUncheckedCreateInput`Yunbo
10/06/2022, 3:38 AM$queryRaw
nested object.
is there any way i can get nested object from $queryRaw
for example,
prismaClient.$queryRaw`
SELECT
users.id, users.name,
user_statuses.id AS "userStatus[id]",
user_statuses.name AS "userStatus[name]"
FROM users
INNER JOIN user_statuses ON user_statuses.id = user.status_id
WHERE users.id = ${userId}
`
expected result
[
{
id: 1,
name: "test user",
userStatus: {
id: 1,
name: "verified"
}
}
]
NOTE: I explicitly want to use $queryRaw
Daniele
10/06/2022, 8:20 AMTaylor Lindores-Reeves
10/06/2022, 9:56 AMSlackbot
10/06/2022, 11:35 AMQuentin Laffont
10/06/2022, 12:37 PMKyle Gammon
10/06/2022, 1:14 PMZakaria Mofaddel
10/06/2022, 2:06 PMError: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
Pat
10/06/2022, 2:19 PM*
- I'm sure has been answered many times before, but I'm having a hard time googling for the answer!Balázs Szalay
10/06/2022, 2:30 PMBen Guthrie
10/06/2022, 3:48 PMBryon Mapes
10/06/2022, 3:56 PMTransaction
await update value A to 2
await update value A to 2
End Transaction
Ty-Lucas Kelley
10/06/2022, 3:58 PMhashids
and Prisma - https://github.com/prisma/prisma/discussions/10588
We're finding that our adoption to Prisma is resulting in far more boilerplate than we want, for two reasons:
1. Lack of support for generics
2. Lack of support for something like TypeORM's transformer
argument to a column definition
Our desire is to be able to have a model that looks like this:
model Foo {
id Int @id @default(autoincrement())
}
But be able to use hashids
so that the IDs are represented as encoded strings for any client code, so we could do this:
const foo = await prisma.foo.findUnique({ where: { id: "some string" })
And some string
would be decoded to the underlying database ID. We haven't figured out a middleware solution for doing this, resulting in a lot of extra effort spent calling encodeId
and decodeId
all over the place whenever we're passing primary/foreign keys from the client to the server. Anyone have solid ideas or examples for how to do this efficiently? Not ruling out a middleware solution, just haven't found a good way to do itMatheus Assis
10/06/2022, 8:05 PMnexus-plugin-prisma
from our project following the guide: https://nexusjs.org/docs/plugins/prisma/removing-the-nexus-plugin-prisma#migrating-from-tcrud-to-plain-nexus
The issue is that it’s messing up null
and undefined
types
We converted the types using the SDL converter, but when we provide the args
variable to prisma, it complains of nullability because graphql returns those as null but prisma don’t expect them to be null.
Even when following the “Pagination, filtering, sorting” section on the guide. The guide just does a cursor: args.cursor || undefined
. But that seems to be wrong, instead, we’d have to manually destructure the `cursor`(like done with the where
). The issue is that the where
could be anything, the orderby
could be anything, and until how many nested values should we destructure?
Is there a better way of handling this? How one should do it? Is the doc outdated?
Also, we saw this https://github.com/graphql-nexus/nexus-plugin-prisma/blob/main/src/null.ts. Would that be the recommended approach?
cc: @Adarley GrandoTed Joe
10/06/2022, 9:29 PMAJ Holloway
10/06/2022, 9:31 PMЛеонид Шабалкин
10/07/2022, 6:45 AMRichard Scarrott
10/07/2022, 10:33 AMconsole.log(prisma.user.findUnique === prisma.user.findUnique); // EXPECT: true, ACTUAL: false
I think it's caused by the use of getters or maybe Proxy
?Oliver St.
10/07/2022, 12:18 PMconnection_limit
of prisma if you don’t specify one in the DATABASE_URL
?Matt
10/07/2022, 1:42 PMmodel Area {
id String @id @default(cuid())
name String
type AreaType
code String
intersects Area[] @relation("AreaIntersects")
}
Where intersects
is self-referencing the model, but the VSCode plugin keeps trying to correct it by adding additional rules (which it also doesn’t seem to like)Joey
10/07/2022, 2:41 PMconst user = await db.user.findFirst({
where: { id: user.id },
include: {
blogs: true,
<specific blog with relations>: { where: { id }, include { ... } }
}
});
Jonathan Marbutt
10/07/2022, 2:48 PM