Jarupong
09/25/2022, 9:11 AMJoey
09/25/2022, 3:22 PMconst blogs = await prisma.blogs.findMany({where: { userId }, include: {user:true}});
is prisma / sql smart enough so that it won’t do a join on every single one of the results, since it will always be the same userId/user?
if not, is it recommended to just fetch that user once in a separate query?Ashe Magalhaes
09/25/2022, 4:26 PMDavid Van Isacker
09/26/2022, 1:04 AMYudhvir Raj
09/26/2022, 2:07 AMYudhvir Raj
09/26/2022, 2:11 AMDavid Ilizarov
09/26/2022, 5:27 AMprisma.model.update({
where: {
id: 10
},
data: {
array: {
push: [1,2,3,4]
}
}
})
The above would presumably push 4 numbers onto the array on my model.
The documentation says otherwise belowA. Sauder
09/26/2022, 6:51 AMthomas dicola
09/26/2022, 8:50 AMthomas dicola
09/26/2022, 8:50 AMRémi
09/26/2022, 9:16 AMSELECT a.id, a.title
FROM a
INNER JOIN ON a.nextSession = b.id
INNER JOIN ON b.id = c.tutelageSession
INNER JOIN ON c.user = d.id
WHERE d.name NOT 'VALUE';
Here my tables :
| a (TutelageClass) | b (TutelageSession) | c | d (User) |
| ------------------- | ----------------------- | ----------------------- | --------- |
| id | id | #user | id |
| title | title | #tutelageSession | name |
| #nextSession |
My Prisma schema is the following (simplified) :
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model TutelageClass {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
nextSessionId String? @db.ObjectId
nextSession TutelageSession?
}
model TutelageSession {
id String @id @default(auto()) @map("_id") @db.ObjectId
registeredStudentsIDs String[] @db.ObjectId
tutelageClassId String @unique @db.ObjectId
tutelageClass TutelageClass @relation(fields: [tutelageClassId], references: [id], onUpdate: Cascade, onDelete: Restrict)
registeredStudents User[] @relation("RegisteredStudentsToTutelageSession", fields: [registeredStudentsIDs], references: [id])
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
registeredToTutelageSessionIDs String[] @db.ObjectId
registeredToTutelageSession TutelageSession[] @relation("RegisteredStudentsToTutelageSession", fields: [registeredToTutelageSessionIDs], references: [id])
}
And finally, the code I'm trying :
const c = await client.tutelageClass.findMany({
select: {
id: true,
title: true,
}, where: {
nextSession: {
registeredStudents: {
none: {
id: userIdNotRegistered
}
}
}
}
});
Bablu Ahmed
09/26/2022, 9:59 AMRicardo Ferreira
09/26/2022, 10:24 AMprisma migrate reset
but that recreates all the migrations and I just want to be able to trash all the migrationsMatheus Assis
09/26/2022, 12:03 PMVladi Stevanovic
Mordechai Tzarfati
09/26/2022, 3:07 PMNurul
09/26/2022, 3:25 PMHi there! New to this channel so please redirect me if this should go elsewhere.
I’m using prisma with a mysql planetscale backend.
I’m getting an error about ROW_NUMBER() in aprisma.$queryRaw
Something like this, which works fine on my planetscale console:
Copy codeconst query = `select ROW_NUMBER() over() FROM contacts`;
Results in the error:
Copy codeCode: `1105`. Message: `unknown error: syntax error at position 26`
Anyone know why prisma can’t seem to handlefunction?ROW_NUMBER()
Vladi Stevanovic
Hey all, I'm trying to use prisma along with this article to create a multi tenant application. I have everything setup, but when I try to migrate, I can't create tables in other schemas in my database.
When I try to run a query likeI get an error like.create
Copy codeThe table `e874649f-ac3e-47c0-bbd5-994fdd7dc116.User` does not exist in the current database.
which makes sense.
Im new to prisma so I was wondering if anyone had any ideas on how I could create the tables specified inin my db when I run migrateschema.prisma
Peter
09/26/2022, 4:21 PMorderBy
clause does not take into account the relations joined with include
and where
?MrDrummer25
09/26/2022, 7:13 PMNathan
09/26/2022, 7:17 PMError: Schema validation error - Error (query-engine-node-api library)
Error code: P1012
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:12
|
12 | url = env("DATABASE_URL")
|
Validation Error Count: 1
[Context: getConfig]
Prisma CLI Version : 4.3.1
sean oreilly
09/26/2022, 8:48 PMuserId
)`
• the thing that is confusing to me is that I have other modals that are setup very similarly and this is just causing me a lot of confusion.
This is my code:
const fakers = await Promise.all(
new Array(10).fill(1).map(async () => {
return {
email: faker.internet.email(),
name: faker.name.fullName(),
id: faker.datatype.string(),
username: faker.internet.userName(),
image: faker.internet.avatar(),
}
})
)
const fakeUsers = await Promise.all(
fakers.map(async (user) => {
return prisma.user.upsert({
where: { email: user.email },
update: {},
create: {
email: user.email,
name: user.name,
image: user.image,
username: user.username,
},
})
})
)
const suggestions = await Promise.all(
fakeSuggestions.map(async (suggestion, i) => {
return prisma.suggestion.upsert({
where: { title: suggestion.title },
update: {},
create: {
title: suggestion.title,
description: suggestion.description,
user: {
connect: {
id: fakeUsers[Math.floor(Math.random() * fakeUsers.length)].id,
},
},
category: {
connect: {
id: cats[Math.floor(Math.random() * cats.length)].id,
},
},
status: {
connect: {
type: stats[Math.floor(Math.random() * stats.length)].type,
},
},
},
})
})
)
// Votes
await Promise.all(
new Array(100).fill(1).map(async (i) => {
return prisma.vote.upsert({
where: {
id: Math.floor(Math.random() * 1000),
},
update: {},
create: {
user: {
connect: {
id: fakeUsers[Math.floor(Math.random() * fakeUsers.length)].id,
},
},
suggestion: {
connect: {
id: suggestions[Math.floor(Math.random() * suggestions.length)]
.id,
},
},
},
})
})
)
sean oreilly
09/26/2022, 8:48 PMNathan N
09/26/2022, 9:54 PMEric Simon
09/26/2022, 11:36 PM// Inferred type:
// User & {
// posts: Post[];
// }
const user = await prisma.user.create({
data: {
email: '<mailto:alice@prisma.io|alice@prisma.io>',
password: '0ee4808f893b8e05bdd251048d5c4c8af8bb89403676dda95619841a481f8e87',
name: 'Alice',
posts: {
create: {
title: 'Learn how to use Prisma with TypeScript',
content: '<https://www.prisma.io/docs/>',
},
},
},
include: {
posts: true,
},
})
Nurul
09/27/2022, 11:02 AMNurul
09/27/2022, 11:30 AMMuhammed Hafiz
09/27/2022, 11:48 AM{
"_id": {
"$oid": "61cd48ae528ffa2b3e44010e"
},
"name": {
"en": "Arwa Water 24 X 500ml",
"ar": "AR content ",
},
"description": {
"en": "Stay hydrated in a healthy way with this water, It is sure to quench your thirst and nourishes your body with all the essential vitamins and minerals"
},
*mrp*: 17,
*stock*: 100,
*packing*: "24"
}
Currently i use mongoose
and mongoose-intl
to retrieve language only data like this according to the language set, is it possible to achieve this with Prisma?
if not, what are the alternatives?
{
"_id": {
"$oid": "61cd48ae528ffa2b3e44010e"
},
"name": "Arwa Water 24 X 500ml",
"description": "Stay hydrated in a healthy way with this water, It is sure to quench your thirst and nourishes your body with all the essential vitamins and minerals",
*mrp*: 17,
*stock*: 100,
*packing*: "24"
}
Timo
09/27/2022, 11:52 AMdoddy nicolas
09/27/2022, 2:54 PM