Yaakov
08/11/2022, 2:46 PMRoded Konforty
08/11/2022, 3:23 PMRoded Konforty
08/11/2022, 3:24 PMRoded Konforty
08/11/2022, 3:24 PMRoded Konforty
08/11/2022, 3:24 PMTed Joe
08/11/2022, 3:36 PMUser {
id: 394993
...
userAddress: [Address, Address, Address]
}
Address {
id: 393932
...
}
Michael Gates
08/11/2022, 6:37 PMIn the postinall hook of this package, all engines available for the current platform are downloaded from the Prisma CDN
But I want to download for all platforms, not just the current.heliosalves
08/11/2022, 7:12 PMQuotation
and one Invoice
, these two models are very similar and I can create a quotation and once the quotation is accepted, I can create an invoice for this quotation. When I create the quotation I’d like to be able to add sections and items to these sections.
When I create an invoice I can either attach a quotation to this invoice or add sections and items to these sections. I took a look at the documentation on Prisma for the many-to-many relationships https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations, but I’m unsure how to do this when two tables depend on this.
In my case I want to have a many-to-many relationship between Quotation
, Section
and SectionItem
and Invoice
, Section
SectionItem
Here are the models I’ve created so far
model Client {
id String @id @default(uuid())
name String
street String
postalCode String
city String
email String
typeId String
type ClientType @relation(fields: [typeId], references: [id], onDelete: Restrict)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
phoneNumberMobile String?
phoneNumberLandLine String?
invoices Invoice[]
quotations Quotation[]
}
model ClientType {
id String @id @default(uuid())
value String
clients Client[]
}
model Category {
id String @id @default(uuid())
value String
stocks Stock[]
services Service[]
}
model Stock {
id String @id @default(uuid())
name String
quantity Int @default(0)
price Float @default(0)
categoryId String
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
}
model Invoice {
id String @id @default(uuid())
number Int @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
invoiceStatusId String
status InvoiceStatus @relation(fields: [invoiceStatusId], references: [id], onDelete: Restrict)
dueOn DateTime
validUntil DateTime
clientId String
client Client @relation(fields: [clientId], references: [id], onDelete: NoAction)
quotationId String? @unique
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: NoAction)
sections Section[]
}
model Quotation {
id String @id @default(uuid())
number Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
invoiceStatusId String
validUntil DateTime
clientId String
client Client @relation(fields: [clientId], references: [id], onDelete: NoAction)
invoice Invoice?
sections Section[]
}
model InvoiceStatus {
id String @id @default(uuid())
value String
invoices Invoice[]
}
model Service {
id String @id @default(uuid())
name String
price Float
categoryId String
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
}
model SectionUnit {
id String @id @default(uuid())
value String
serviceSections Section[]
}
model SectionItem {
id String @id @default(uuid())
name String
description String @db.Text
serviceSectionId String
sections Section[]
}
model Section {
id String @id @default(uuid())
name String
items SectionItem[]
unitId String
unit SectionUnit @relation(fields: [unitId], references: [id], onDelete: Restrict)
quotationId String?
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: NoAction)
invoiceId String?
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: NoAction)
}
I’m not sure if this is the correct approach, any help would be appreciated 🙂 Thank youTyler C
08/11/2022, 7:31 PMAlbert Montolio
08/11/2022, 8:32 PMdate
type using nestjs
app with prisma
and using postgresql
as db
. I opened this discussion on prisma’s github for further details on the question.
Basically I’m struggling to understand what date object
to pass to the this.prisma.user.create({ data: {date: XXX}})
. I define the field date
as DateTime @db.Date
in thet prisma schema.
But Postgresql
wants a date object with format 'YYYY-MM-DD',
but I’m in a nestjs
app, I can’t pass a string, since prisma is expecting a date object. If I do sth like new Date()
with whatever format, like iso and so on, it stills doesn’t correspond to the 'YYYY-MM-DD'
, I can only obtain this if I pass a string, but then prisma complains.
Could someone guide me on that topic? In the docu I just found this, but this just works purely with postgresql, not with the prisma client. Thanks!Dave Edelhart
08/11/2022, 10:33 PMJustin F
08/12/2022, 1:43 AMNurul
08/16/2022, 9:03 AMEnzot
08/12/2022, 9:17 AM100n
for BigInt? I wonder if I can somehow remove that n
automaticallyJhonathan Campos
08/12/2022, 9:19 AMHussam Khatib
08/12/2022, 9:35 AMdistinct
where a column can be null too.
Expected Behaviour : if value is not null , perform using it normal behaviour of distinct. If value is null I want this to be returned as well.Bastien Etienne
08/12/2022, 10:23 AMupsert
for Create if id not exist. So actually update work fine but when id not exist , the create part return me this error :
:42:29) {
code: 'P2023',
clientVersion: '4.0.0',
meta: {
message: 'Error creating UUID, invalid length: expected one of [36, 32], found 35'
}
}
This is the code
const updateFeature = await prisma.feature.upsert({
where: {
id: props.idFeature,
},
update: {
cibest_role_id: roleId.id,
create: props.create,
read: props.read,
update: props.update,
delete: props.delete,
service_name: props.service_name,
},
create: {
cibest_role_id: roleId.id,
create: props.create,
read: props.read,
update: props.update,
delete: props.delete,
service_name: props.service_name,
},
});
this is the feature model
model feature {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
date_created DateTime @default(now()) @db.Timestamp(6)
service_name service_name
create Boolean @default(false)
read Boolean @default(false)
update Boolean @default(false)
delete Boolean @default(false)
cibest_role_id String @db.Uuid
iconId String? @db.Uuid
cibest_role cibest_role @relation(fields: [cibest_role_id], references: [id])
icon icon? @relation(fields: [iconId], references: [id])
}
Phorcys
08/12/2022, 11:50 AMmodel Classroom {
id String @id @default(cuid())
type Int @default(0)
name String
teachers Teacher[] // when a teacher is added, append to the teacher's "classes" attribute
}
model Teacher {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique
classes Classroom[] // when a class is added, add the teacher to the matching class' "teachers" attribute
subjects Subject[]
}
Phorcys
08/12/2022, 11:52 AMMichael Jay
08/12/2022, 1:18 PMSlackbot
08/12/2022, 5:33 PMheliosalves
08/12/2022, 6:31 PMSection
and this table is linked to another table SectionItem
, I have two other tables, Quotation
and Invoice
and I want to be able to add sections and sectionItems to either Quotation
or Invoice
. Is this even possible? How could I do this in Prisma? How can I create a model that allows me to do this?
Thank younick
08/12/2022, 7:56 PMAbdul Khan
08/12/2022, 11:22 PMAbdul Khan
08/12/2022, 11:22 PMType: undefined
Message:
Invalid `prisma.menu.create()` invocation:
{
data: {
id: 4,
~~
name: 'Brunch',
resteraunt: {
connect: {
id: 1
}
}
},
select: {
id: true,
name: true,
resteraunt: true,
resterauntId: true
}
}
Unknown arg `id` in data.id for type MenuCreateInput. Available args:
type MenuCreateInput {
name?: String | Null
resteraunt: ResterauntCreateNestedOneWithoutMenuInput
}
Code: undefined
Query:
[object Object]
Abdul Khan
08/12/2022, 11:24 PMmenu
and still resulted in the same errorItalo Gama
08/13/2022, 1:38 AMItalo Gama
08/13/2022, 2:16 AMHussam Khatib
08/13/2022, 4:20 AMOR
filter in where clause in such way that the first condition in OR
is checked throughout the db and if it does not exist try with the second one.
const result = await prisma.findFist({
where:{
OR:[
{"condition 1"},{"condition 2"}
]
}
})
If filter condition 1 is not matched with any record , then only try for condition 2Clément Guibout
08/13/2022, 2:26 PMmodel Event {
evt_id String @id @default(uuid())
...