Here I have two models, a venue and an address. Would it be better practise to have the venue address within the venue model or is it best to keep them separate? The second question would be how do I create a venue with a linked address? Having read the Prisma documentation I can not seem to find the answer I am looking for. I am getting errors from the pine that icludes propertyNumber like so
Type '{ title: string; images: string[]; address: { propertyNumber: string; }; }' is not assignable to type '(Without<VenueCreateWithoutUserInput, VenueUncheckedCreateWithoutUserInput>
await prisma.user.create({
data: {
name: 'Samss',
email: '[email protected]',
Venue: {
create: {
title: 'new venue',
images: ['https://cdn.pixabay.com/photo/2023/01/31/05/59/zebra-7757193_960_720.jpg'],
address: {
propertyNumber: "12"
},
}
},
},
})
model Venue {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
address Address? @relation(fields: [addressId], references: [id])
published Boolean @default(false)
userId String
images String[]
user User @relation(fields: [userId], references: [id])
addressId String?
}
model Address {
id String @id @default(cuid())
propertyNumber String
firstLine String
Area String
Country String
zipCode String
lat Decimal
lng Decimal
Venue Venue[]
}
I'd say that it will depend on how often you will need the venues without the address? If it's never, just put the address fields inside the venue.
Remember, that each model will result in a single table, and accessing each venue with its address will join both tables, resulting in poor performance over time.
Regarding your error, it might come from your 1-N relation between Venue
and Addres
. You should have a 1-1.
Just put the address in your Venue, and you'll be fine.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments