Akash Anand
01/23/2022, 9:53 AMAdrian
01/23/2022, 10:26 AMAdrian
01/23/2022, 10:27 AMLars Ivar Igesund
01/23/2022, 10:32 AMLars Ivar Igesund
01/23/2022, 10:32 AMAdrian
01/23/2022, 10:39 AMLars Ivar Igesund
01/23/2022, 10:43 AMManish
01/23/2022, 11:48 AMconst users = await prisma.user.findMany({
include: {
posts: true
},
})
Is it possible to limit the number of posts that are returned. For example, can I limit it to 10 posts for that user to be included in the relation?Rich Starkie
01/23/2022, 5:14 PMprisma.<table>.<action>
so I can reuse a funtion for multiple tables?Salvage
01/23/2022, 7:08 PMLars Ivar Igesund
01/23/2022, 7:33 PMSalvage
01/23/2022, 7:50 PMRaj Chaudhary
01/24/2022, 5:46 AMmodel User {
id BigInt @id
createdAt DateTime @db.Timestamptz(3) @default(now())
updatedAt DateTime @db.Timestamptz(3) @updatedAt
accountId BigInt
account Account @relation(fields: [accountId], references: [id])
fullName String
email String
oauthToken String?
}
The generated sql file is as follows:
CREATE TABLE "User" (
"id" BIGINT NOT NULL,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
"accountId" BIGINT NOT NULL,
"fullName" TEXT NOT NULL,
"email" TEXT NOT NULL,
"oauthToken" TEXT,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
However prisma client does not mark the User.oauthToken as nullable in TS. Can anyone help?Thibaut De Maerteleire
01/24/2022, 7:58 AMHubert Kowalski
01/24/2022, 8:35 AMNathaniel Bajo
01/24/2022, 10:10 AMNathaniel Bajo
01/24/2022, 10:11 AMNathaniel Bajo
01/24/2022, 10:12 AMNathaniel Bajo
01/24/2022, 10:12 AMNathaniel Bajo
01/24/2022, 10:13 AMNathaniel Bajo
01/24/2022, 10:13 AMNathaniel Bajo
01/24/2022, 10:14 AMNathaniel Bajo
01/24/2022, 10:15 AMgit cloned
the prisma engine repo and `cargo build --release`ed it on my raspberry piNathaniel Babalola
01/24/2022, 10:38 AMElijah Rosier
01/24/2022, 10:50 AMnumber
when in reality it returns { _count: { _all: 14 } }
?
prisma.sentimentResponse.count({
where: {
contentId: pathParameters.contentId,
},
})
Is there something I'm doing wrong? I'm not casting it anywhereNathaniel Babalola
01/24/2022, 11:29 AMAlexSPx
01/24/2022, 11:31 AMmodel Course {
name String @id @unique
public_name String?
details Json?
published Boolean @default(false)
model ModelType @default(WEEKLY)
weeks Int?
// Relation Fields
members CourseEnrollment[]
dataModels CourseDataModel[]
@@map("course")
}
model CourseDataModel {
id String @id @default(uuid())
name String
type DataType
props Json
// Relation Fields
document_id String? @unique
document Document? @relation(fields: [document_id], references: [id], onDelete: Cascade)
video_id String? @unique
video Video? @relation(fields: [video_id], references: [id], onDelete: Cascade)
course_id String
course Course @relation(fields: [course_id], references: [name], onDelete: Cascade)
assignment_id String? @unique
assignment Assignment? @relation(fields: [assignment_id], references: [id], onDelete: Cascade)
quiz_id String? @unique
quiz Quiz? @relation(fields: [quiz_id], references: [id], onDelete: Cascade)
@@map("courseDataModel")
}
^^^ This is my prisma schema
Is there a way to write a query that selects all the courses and count each dataModel where the value of "document_id" is not undefinedAlexSPx
01/24/2022, 11:31 AMconst courses = await prismaClient.course.findMany({
where: {
published: true
},
select: {
name: true,
public_name: true,
details: true,
weeks: true,
},
include: {
_count: {
select: {
dataModels: {
where: {...}
}
}
}
}
})
Something like thisStijn
01/24/2022, 12:59 PMInvalid `prisma.project.update()` invocation:
The change you are trying to make would violate the required relation 'ProjectToUserProject' between the `Project` and `UserProject` models.
details:
{
code: 'P2014',
clientVersion: '3.8.1',
meta: {
relation_name: 'ProjectToUserProject',
model_a_name: 'Project',
model_b_name: 'UserProject'
}
}
This is my schema.prisma:
model UserProject {
projectId Int
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, projectId])
}
model Project {
id Int @id @default(autoincrement())
name String
users UserProject[]
}
This is the code:
const project = await db.project.update({
where: { id },
data: {
...data,
users: {
set: users?.map(user => ({
userId_projectId: {
userId: user.userId,
projectId: id,
},
}))
}
},
})
Shmuel
01/24/2022, 8:54 PMbeforeEach(async () => {
await prisma.$queryRaw`BEGIN TRAN`;
});
afterEach(async () => {
await prisma.$queryRaw`ROLLBACK TRAN`;
});
I'm getting the following error.
Raw query failed. Code: `266`. Message: `Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0.`
How can I accomplish this?