Nathaniel Babalola
08/18/2021, 9:39 AMmodel Traveller {
travellerId Int @id @default(autoincrement())
title String
firstName String
lastName String
countryCode String
phoneNo String
address String
state String
country String
bookingRef String
travellerType String? @default("adult")
price String
currency String
isUser Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int? // relation scalar field (used in the '@relation()` attribute below)
user User? @relation(fields: [userId], references: [id])
flightBooking FlighBooking @relation(fields: [bookingRef], references: [bookingRef])
@@map(name: "traveller")
}
model FlighBooking {
bookingRef String @id
userId Int?
email String
countryCode String
phoneNo String
flightType String
price Int
currency String
status String?
paymentId String?
adultCount Int
childCount Int
infantCount Int
childDOB String
airlinePNR String?
ticketNo String?
vendorPNR String?
vendorType String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id])
travellers Traveller[]
flightPostBooking FlightPostBooking[]
@@map(name: "flightBooking")
}
Please who knows how I can perform a CROSS JOIN across these two tables with Prisma?
searching for a single record with a traveller's lastName
AND bookingRef
OR airlinePNR
or vendorPNR
.
The two tables are only joined via bookingRef
Ryan
08/18/2021, 10:14 AMawait prisma.traveller.findFirst({
where: {
OR: [
{
AND: [{ lastName: 'lastname' }, { bookingRef: 'ref' }],
},
{ flightBooking: { airlinePNR: 'AirlinePNR' } },
{ flightBooking: { vendorPNR: 'VendorPNR' } },
],
},
})
Nathaniel Babalola
08/18/2021, 10:19 AMRyan
08/18/2021, 10:21 AMawait prisma.traveller.findFirst({
where: {
OR: [
{
AND: [
{ lastName: 'lastname' },
...(bookingRef && { bookingRef }),
],
},
{ flightBooking: { airlinePNR: 'AirlinePNR' } },
{ flightBooking: { vendorPNR: 'VendorPNR' } },
],
},
})
Nathaniel Babalola
08/18/2021, 10:30 AM...(bookingRef && { bookingRef })
Ryan
08/18/2021, 10:32 AMNathaniel Babalola
08/18/2021, 10:46 AMRyan
08/18/2021, 11:36 AMOR
and AND
operator. The spread operator was just JavaScript that I used and that wouldn’t be present in the docs.