Jakub Figlak
03/16/2022, 7:34 PMmodel Organization {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relation fields
members User[]
}
I'm gonna create a route to create an organization that accepts body:
name: string
memberIds: string[]
So basically I want to create relations from the many
side of the many-to-one
relation (user can be a member of only one organization at the given point in time). And here's my question - what is the best way to ensure that? Do I need to query for all users, check if they're already members of other organization and if they're, reject an entire request? Or is there a simpler way?Aderito Timane
03/16/2022, 8:37 PMCREATE TABLE [Movie] (
[id] int PRIMARY KEY,
[title] nvarchar(255)
)
CREATE TABLE [User] (
[id] int PRIMARY KEY,
[username] nvarchar(255)
)
CREATE TABLE [Theater] (
[id] int PRIMARY KEY,
[theatre_name] nvarchar(255)
)
CREATE TABLE [Schedule] (
[id] int PRIMARY KEY,
[sdt] datetime,
[movieId] int REFERENCES Movie (id),
[userId] int REFERENCES User (id),
[theatreId] int REFERENCES Theater (id)
)
versus the equivalent prisma.schema
model Movie {
id Int @id @default(autoincrement())
title String
Schedule Schedule[]
}
model User {
id Int @id @default(autoincrement())
name String
Schedule Schedule[]
}
model Theatre {
id Int @id @default(autoincrement())
name String
Schedule Schedule[]
}
model Schedule {
id Int @id @default(autoincrement())
movieId Int
theatreId Int
userId Int
date DateTime
movie Movie @relation(fields: [movieId], references: [id])
theatre Theatre @relation(fields: [theatreId], references: [id])
user User @relation(fields: [userId], references: [id])
}
I notice that all Theatre, User and Movie have to reference Schedule in Prisma. However I don't have to do similar when it comes to SQL.
Is there a way to achieve this SQL simplicity?
I'm open to learning about the reason for this design if there are better reasons I should rather follow this format. However, I have a simple approach to design the database where I'm happy to be making multiple calls for related data within the BFF. Further, I have some tables that have two or three relationships related to them and it becomes a less nice to read so much information stuck into just one model.Eric N.
03/17/2022, 4:15 AMEric N.
03/17/2022, 4:17 AMJulian
03/17/2022, 7:51 AMJoshua Snyder
03/17/2022, 10:48 AMMellonaut
03/17/2022, 1:25 PMdev
but, running deploy returns this error in the browser: Uncaught TypeError: Failed to resolve module specifier ".prisma/client/index-browser". Relative references must start with either "/", "./", or "../".
I am instantiating Prisma in $lib/prisma.ts
like this:
import Prisma, * as PrismaAll from '@prisma/client'
const pc = Prisma?.PrismaClient || PrismaAll?.PrismaClient
export const prisma = new pc()
and importing it in there from my endpoints.
I’m using adapter_vercel
to deploy to vercel
Any idea what might be the issue here?Ayrton Fidelis
03/17/2022, 2:22 PMcreatedAt
date that I think I should group by, but I need it to be grouped by the year-month of this date, ignoring the day/time. With Postgres I think the DATE_TRUNC('month', createdAt)
would be perfect but I'm not allowed to group by that on Prisma. I even tryied to cast it to Prisma.WorkerScalarFieldEnum
but in the runtime it told me this wasn't allowed. Really would appreciate any guidance someone could provide me to achieve that, specially if I don't have to change the database schema for that 😅
Here's what my best attempt looks like:Mischa
03/17/2022, 3:26 PMRafael
03/17/2022, 8:05 PMsuperbunches
03/17/2022, 8:22 PMInvalid `prisma.book.findMany()` invocation:
{
include: {
moods: true,
~~~~~
? pairings?: true,
? _count?: true
}
}
Unknown field `moods` for include statement on model Book. Available options are listed in green. Did you mean `_count`?
This doesn’t make sense to me because npx prisma migrate dev
went fine, I’ve seeded my database using the new model name, and I’ve confirmed in postgres that the new table (Mood
) is there. Why would I get this error with the new field name and not the old field name?
Running prisma 3.11.0 & @prisma/client 3.11.0Travis Beck
03/17/2022, 9:18 PMselect
user_id,
sum(coalesce((properties->>'duration')::integer, 0)) as connection_duration
from
events
where
doc_id = '123'
and event = 'disconnect'
group by
user_id
I guess an interface I would want is something like this, but I think prisma would need to know more about the types in the json to be able to give it back to me:
const events = await this.prisma.event.groupBy({
by: ['userId'],
where: {
docId: '123',
event: 'disconnect',
},
_sum: {
'properties->>duration': true
},
})
Are there any reasonable workaround here, or do I just need to use a raw query?Bamada
03/17/2022, 9:40 PM(user, team)
on the memberships
table.
My aim is to use something like INSERT IGNORE INTO ....
Is there a better way to do that?
await prisma.membership.create({
data: {
permission: membership.permission.toUpperCase() as any,
role: membership.role,
state: MembershipState.JOINED,
joinedAt: membership.createdAt,
requestedAt: membership.updatedAt,
user: {
connect: {
username: membership.user.username
}
},
team: { connect: { slug: membership.team.slug } }
}
Thanks in advanceOrcioly Andrade Alves
03/17/2022, 10:20 PMDamian M
03/18/2022, 12:29 AMGeert van Dijk
03/18/2022, 11:14 AMCezar Rodrigues
03/18/2022, 12:06 PMOleg Rudak
03/18/2022, 12:40 PMgenerator client {
provider = "prisma-client-js"
previewFeatures = ["dataProxy", "referentialIntegrity", "fullTextSearch", "fullTextIndex"]
}
model User {
username String?
email String?
@@fulltext([username, email])
@@fulltext([username])
@@fulltext([email])
}
Migration:
-- CreateIndex
CREATE INDEX `User_username_email_idx` ON `User`(`username`, `email`);
-- CreateIndex
CREATE INDEX `User_username_idx` ON `User`(`username`);
-- CreateIndex
CREATE INDEX `User_email_idx` ON `User`(`email`);
Also I have run yarn prisma db push
But I still get error P2030: Cannot find a fulltext index to use for the search
when trying to search by any field:
return await prisma.user.findMany({
where: {
username: input?.username && { search: input.username },
email: input?.email && { search: input.email },
type: input?.type,
},
select: {
...getSharedSelectableFields(),
},
take: input?.take,
skip: input?.skip,
});
Why this can happen?
Prisma version: 3.8.1Jason Kleinberg
03/18/2022, 2:15 PMdb-testing-pool
. I haven’t been able to find it. Does anyone know what she was talking about?
Alternatively, I could use some advice on integration testing with Prisma in a way that won’t have our test data collide.
aj
03/18/2022, 8:21 PMMischa
03/19/2022, 1:19 PMDavid Marr
03/19/2022, 6:51 PMts-node ./script.ts
successfully, since it doesn't appear to define type: 'module'
in package.json and it uses top-level import
David Marr
03/19/2022, 6:51 PMDavid Marr
03/19/2022, 7:16 PMmodule: "CommonJS"
inside ts-config.json fixes itLudde Bror
03/20/2022, 8:13 AMmodel Order {
id Int @id @unique @default(autoincrement())
products Product[] @relation(references: [id])
}
model Product {
id Int @id @unique @default(autoincrement())
orders Order[] // Why do I need this here? I don't really care about this, I only care about the above, products in an order. Can I get rid of this line somehow?
}
Another thing, how can I reference a product in an order entry, and at the same time set some additional information about it, such as the quantity of a referenced product?Jawad Sefiani
03/20/2022, 11:02 PMFenibo fubara
03/21/2022, 4:53 PMHenry Luu
03/21/2022, 5:14 PMOther side is closed
error in the response. I tried so hard but couldn't find any root causes in our code.
I found this closed issue from Github, but we didn't call $disconnect
like the guy who created the bug did https://github.com/prisma/prisma/issues/5888
Can you help guide me about this issue please? 🙏
If I didn't call $disconnect
, could anything else cause the error of Other side is closed
in Prisma response?Atticus Curtis
03/21/2022, 6:55 PMAtticus Curtis
03/21/2022, 6:56 PM