```model Traveller {   travellerId   Int          ...
# orm-help
n
Copy code
model 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")
}
Copy code
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
r
@Nathaniel Babalola 👋 Have you tried this?
Copy code
await prisma.traveller.findFirst({
    where: {
      OR: [
        {
          AND: [{ lastName: 'lastname' }, { bookingRef: 'ref' }],
        },
        { flightBooking: { airlinePNR: 'AirlinePNR' } },
        { flightBooking: { vendorPNR: 'VendorPNR' } },
      ],
    },
  })
n
I considered this, but didn't know how to nest it. My concern was that , only one of bookingRef, airlinePNR and vendorPNR will be available from req.query. @Ryan
r
Conditions can be added like this:
Copy code
await prisma.traveller.findFirst({
    where: {
      OR: [
        {
          AND: [
            { lastName: 'lastname' },
            ...(bookingRef && { bookingRef }),
          ],
        },
        { flightBooking: { airlinePNR: 'AirlinePNR' } },
        { flightBooking: { vendorPNR: 'VendorPNR' } },
      ],
    },
  })
n
ooh okay , thanks @Ryan. what's the use of the spread operator you added here?
Copy code
...(bookingRef && { bookingRef })
r
We don’t need the inner object, just the key which is why we need to spread it 🙂
n
Ooh okay. @Ryan, can you link me to a specific part of the docs so I can grasp queries like these better
r
In the docs it would just be the
OR
and
AND
operator. The spread operator was just JavaScript that I used and that wouldn’t be present in the docs.