Skip to content

relationJoins: "The table (not available) does not exist in the current database." #22299

@Crymzix

Description

@Crymzix

Bug description

Updated Prisma from v5.4.2 to v5.7.0 to test out the "relationJoins" preview feature. Most queries work as expected but there was one that gave me this error when executing a findMany operation:

The table `(not available)` does not exist in the current database.

This happens locally and when deployed to App Engine on GCP.

How to reproduce

Upgrade to v5.7.0 and enable the "relationJoins" preview feature.

Expected behavior

The query should "just work" and return the correct data as before when using the previous versions of Prisma.

Prisma information

For brevity I am not including the entire schema and instead including the models that are related to the query in question that has caused the error I am seeing. Let me know if you need me to include more.

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

generator client {
    provider        = "prisma-client-js"
    output          = "../src/generated/client"
    previewFeatures = ["fullTextSearch", "postgresqlExtensions", "relationJoins"]
    extensions      = [pg_trgm]
}

model SalesOrder {
    id                        String               @id @default(uuid())
    internalId                String?
    referenceId               String?
    author                    User                 @relation(fields: [authorId], references: [id])
    authorId                  String
    distributor               Distributor?         @relation(fields: [distributorId], references: [id])
    distributorId             String?
    location                  Location?            @relation("Locations", fields: [locationId], references: [id], onDelete: Cascade)
    locationId                String?
    pickUpLocation            Location?            @relation("PickupLocations", fields: [pickUpLocationId], references: [id], onDelete: Cascade)
    pickUpLocationId          String?
    deliveryPlan              DeliveryPlan?        @relation(fields: [deliveryPlanId], references: [id])
    deliveryPlanId            String?
    company                   Company              @relation(fields: [companyId], references: [id])
    companyId                 String
    salesOrderItems           SalesOrderItem[]
    deliveryDate              DateTime
    paymentMethod             PaymentMethod        @default(CASH)
    distributorAdvancePayment Decimal?             @default(0)
    totalPaidAmount           Decimal?             @default(0)
    totalDueAmount            Decimal?             @default(0)
    totalAmount               Decimal?             @default(0)
    totalBuyingAmount         Decimal?             @default(0)
    transportFareAmount       Decimal?             @default(0)
    discount                  Decimal?             @default(0)
    discountAmount            Decimal?             @default(0)
    deliveryCharge            Decimal?             @default(0)
    additionalNotes           String?
    internalNotes             String[]
    attachments               Attachment[]
    status                    SalesOrderStatus
    subStatus                 SalesOrderSubStatus?
    deliveryStatus            String?
    deliveryTrackingId        String?
    deliveryTrackingUrl       String?
    deliveryOrderId           String?
    deliveryConsignment       Json?
    flagReason                String?
    onHoldReason              String?
    shortId                   Int
    isStockTransfer           Boolean              @default(false)
    isReturn                  Boolean              @default(false)
    transactions              Transaction[]
    parentSalesOrder          SalesOrder?          @relation("SalesOrderChildren", fields: [parentSalesOrderId], references: [id])
    parentSalesOrderId        String?
    salesOrders               SalesOrder[]         @relation("SalesOrderChildren")
    copyCount                 Int                  @default(0)
    staleness                 Int                  @default(0)
    createdAt                 DateTime             @default(now())
    updatedAt                 DateTime             @updatedAt
    orderDate                 DateTime
    exportedForDeliveryAt     DateTime?
    followUpDate              DateTime?
    unloadedAt                DateTime?
    deliveredAt               DateTime?
    approvedAt                DateTime?
    onHoldAt                  DateTime?
    processedAt               DateTime?
    shippedAt                 DateTime?
    inTransitAt               DateTime?
    flaggedAt                 DateTime?
    returnedAt                DateTime?
    damagedAt                 DateTime?
    cancelledAt               DateTime?
    metadata                  Json?
    deliveryArea              Json?
    deliveryPlanItems         DeliveryPlanItem[]
    truckPlateNumber          String?
    loadingBay                String?
    district                  String?
    preferredDeliveryPartner  String?
    deliveryPartner           DeliveryPartner?     @relation(fields: [preferredDeliveryPartner], references: [id])
    source                    OrderSource?         @default(WEBSITE)
    printedAt                 DateTime?
    integration               Integration?         @relation(fields: [integrationId], references: [id])
    integrationId             String?
    isDeliveryFree            Boolean              @default(false)
}

model Location {
    id                                  String                               @id @default(uuid())
    internalId                          String?
    internalName                        String?
    referenceId                         String?
    label                               String?
    description                         String?
    type                                LocationType                         @default(GENERAL)
    address                             String
    district                            String?
    division                            String?
    postCode                            String?
    country                             String?
    contactPerson                       String?
    phone                               String?
    latitude                            Decimal
    longitude                           Decimal
    company                             Company                              @relation(fields: [companyId], references: [id])
    companyId                           String
    deletedAt                           DateTime?
    createdAt                           DateTime                             @default(now())
    updatedAt                           DateTime                             @updatedAt
    locationSalesOrders                 SalesOrder[]                         @relation("Locations")
    pickUpSalesOrders                   SalesOrder[]                         @relation("PickupLocations")
    distributors                        Distributor[]
}

model Distributor {
    id                      String        @id @default(uuid())
    name                    String
    disabled                Boolean       @default(false)
    managerName             String?
    managerTitle            String?
    phone                   String?
    email                   String?
    additionalInformation   String?
    locations               Location[]
    type                    CustomerType  @default(DISTRIBUTOR)
    paymentMethod           PaymentMethod @default(CASH)
    paymentTerms            Int?
    salesOrders             SalesOrder[]
    lastSalesOrderCreatedAt DateTime?
    createdAt               DateTime      @default(now())
    updatedAt               DateTime      @updatedAt
    accountManagerId        String?
    accountManager          User?         @relation("AssignedDistributors", fields: [accountManagerId], references: [id])
    userId                  String
    user                    User          @relation(fields: [userId], references: [id])
    companyId               String
    company                 Company       @relation(fields: [companyId], references: [id])
    shortId                 Int           @unique @default(autoincrement())
    internalId              String?
    internalName            String?
    metadata                Json?
    customerTag             CustomerTag?  @relation(fields: [customerTagId], references: [id])
    customerTagId           Int?
    smsCount                Int           @default(0)
}
const productInclude = {
	productSpecifications: {
		include: {
			specification: {
				select: {
					label: true,
					type: true
				}
			}
		}
	}
} as Prisma.ProductInclude
if (bulkReadSalesOrderDto.inventory) {
	productInclude.inventoryItems = {
		where: {
			quantity: {
				gt: 0
			}
		}
	}
}
const findManyArgs = {
	where: {
		id: {
			in: bulkReadSalesOrderDto.ids
		},
		companyId: cid
	},
	include: {
		company: true,
		deliveryPlan: true,
		distributor: {
			include: {
				accountManager: true,
				locations: {
					where: {
						type: LocationType.BILLING
					}
				}
			}
		},
		location: true,
		pickUpLocation: true,
		transactions: true,
		salesOrderItems: {
			include: {
				product: {
					include: productInclude
				},
				salesOrderItemSpecifications: {
					include: {
						specification: {
							select: {
								label: true,
								type: true
							}
						}
					}
				},
				packaging: true,
				inventoryBatchItem: true
			}
		},
		deliveryPartner: {
			select: {
				id: true,
				name: true,
				type: true,
				partnerId: true,
				disabled: true
			}
		}
	}
} as Prisma.SalesOrderFindManyArgs
const salesOrders = await this.prisma.salesOrder.findMany(findManyArgs)

Here is the generated query from the Prisma logger:

SELECT 
  "t1"."id", 
  "t1"."internalId", 
  "t1"."referenceId", 
  "t1"."authorId", 
  "t1"."distributorId", 
  "t1"."locationId", 
  "t1"."pickUpLocationId", 
  "t1"."deliveryPlanId", 
  "t1"."companyId", 
  "t1"."deliveryDate", 
  "t1"."paymentMethod" :: text, 
  "t1"."distributorAdvancePayment", 
  "t1"."totalPaidAmount", 
  "t1"."totalDueAmount", 
  "t1"."totalAmount", 
  "t1"."totalBuyingAmount", 
  "t1"."transportFareAmount", 
  "t1"."discount", 
  "t1"."discountAmount", 
  "t1"."deliveryCharge", 
  "t1"."additionalNotes", 
  "t1"."internalNotes", 
  "t1"."status" :: text, 
  "t1"."subStatus" :: text, 
  "t1"."deliveryStatus", 
  "t1"."deliveryTrackingId", 
  "t1"."deliveryTrackingUrl", 
  "t1"."deliveryOrderId", 
  "t1"."deliveryConsignment", 
  "t1"."flagReason", 
  "t1"."onHoldReason", 
  "t1"."shortId", 
  "t1"."isStockTransfer", 
  "t1"."isReturn", 
  "t1"."parentSalesOrderId", 
  "t1"."copyCount", 
  "t1"."staleness", 
  "t1"."createdAt", 
  "t1"."updatedAt", 
  "t1"."orderDate", 
  "t1"."exportedForDeliveryAt", 
  "t1"."followUpDate", 
  "t1"."unloadedAt", 
  "t1"."deliveredAt", 
  "t1"."approvedAt", 
  "t1"."onHoldAt", 
  "t1"."processedAt", 
  "t1"."shippedAt", 
  "t1"."inTransitAt", 
  "t1"."flaggedAt", 
  "t1"."returnedAt", 
  "t1"."damagedAt", 
  "t1"."cancelledAt", 
  "t1"."metadata", 
  "t1"."deliveryArea", 
  "t1"."truckPlateNumber", 
  "t1"."loadingBay", 
  "t1"."district", 
  "t1"."preferredDeliveryPartner", 
  "t1"."source" :: text, 
  "t1"."printedAt", 
  "t1"."integrationId", 
  "t1"."isDeliveryFree", 
  "SalesOrder_company"."__prisma_data__" AS "company", 
  "SalesOrder_deliveryPlan"."__prisma_data__" AS "deliveryPlan", 
  "SalesOrder_distributor"."__prisma_data__" AS "distributor", 
  "SalesOrder_location"."__prisma_data__" AS "location", 
  "SalesOrder_pickUpLocation"."__prisma_data__" AS "pickUpLocation", 
  "SalesOrder_transactions"."__prisma_data__" AS "transactions", 
  "SalesOrder_salesOrderItems"."__prisma_data__" AS "salesOrderItems", 
  "SalesOrder_deliveryPartner"."__prisma_data__" AS "deliveryPartner" 
FROM 
  "public"."SalesOrder" AS "t1" 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t4"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t3"."id", 'phone', "t3"."phone", 
                'name', "t3"."name", 'tag', "t3"."tag", 
                'address', "t3"."address", 'latitude', 
                "t3"."latitude", 'longitude', "t3"."longitude", 
                'country', "t3"."country", 'currency', 
                "t3"."currency", 'disabled', "t3"."disabled", 
                'website', "t3"."website", 'createdAt', 
                "t3"."createdAt", 'updatedAt', "t3"."updatedAt"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t2".* 
                FROM 
                  "public"."Company" AS "t2" 
                WHERE 
                  "t1"."companyId" = "t2"."id" 
                  /* root select */
                  ) AS "t3" 
              /* inner select */
              ) AS "t4" 
          /* middle select */
          ) AS "t5" 
      /* outer select */
      ) AS "SalesOrder_company" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t8"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t7"."id", 'internalId', "t7"."internalId", 
                'deliveryDate', "t7"."deliveryDate", 
                'companyId', "t7"."companyId", 'shortId', 
                "t7"."shortId", 'status', "t7"."status", 
                'loadState', "t7"."loadState", 'runIds', 
                "t7"."runIds", 'usableTruckWeights', 
                "t7"."usableTruckWeights", 'createdAt', 
                "t7"."createdAt", 'updatedAt', "t7"."updatedAt", 
                'customized', "t7"."customized", 
                'scalar', "t7"."scalar", 'mode', 
                "t7"."mode", 'cancellationReason', 
                "t7"."cancellationReason"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t6".* 
                FROM 
                  "public"."DeliveryPlan" AS "t6" 
                WHERE 
                  "t1"."deliveryPlanId" = "t6"."id" 
                  /* root select */
                  ) AS "t7" 
              /* inner select */
              ) AS "t8" 
          /* middle select */
          ) AS "t9" 
      /* outer select */
      ) AS "SalesOrder_deliveryPlan" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t12"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t11"."id", 'name', "t11"."name", 
                'disabled', "t11"."disabled", 'managerName', 
                "t11"."managerName", 'managerTitle', 
                "t11"."managerTitle", 'phone', "t11"."phone", 
                'email', "t11"."email", 'additionalInformation', 
                "t11"."additionalInformation", 
                'type', "t11"."type", 'paymentMethod', 
                "t11"."paymentMethod", 'paymentTerms', 
                "t11"."paymentTerms", 'lastSalesOrderCreatedAt', 
                "t11"."lastSalesOrderCreatedAt", 
                'createdAt', "t11"."createdAt", 
                'updatedAt', "t11"."updatedAt", 
                'accountManagerId', "t11"."accountManagerId", 
                'userId', "t11"."userId", 'companyId', 
                "t11"."companyId", 'shortId', "t11"."shortId", 
                'internalId', "t11"."internalId", 
                'internalName', "t11"."internalName", 
                'metadata', "t11"."metadata", 'customerTagId', 
                "t11"."customerTagId", 'smsCount', 
                "t11"."smsCount", 'accountManagerId', 
                "t11"."accountManagerId", 'accountManager', 
                "Distributor_accountManager"."__prisma_data__", 
                'locations', "Distributor_locations_m2m"."__prisma_data__"
              ) AS "__prisma_data__", 
              "t11"."accountManagerId" 
            FROM 
              (
                SELECT 
                  "t10".* 
                FROM 
                  "public"."Distributor" AS "t10" 
                WHERE 
                  "t1"."distributorId" = "t10"."id" 
                  /* root select */
                  ) AS "t11" 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "t16"."__prisma_data__" 
                    FROM 
                      (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'id', "t15"."id", 'internalId', "t15"."internalId", 
                            'name', "t15"."name", 'email', "t15"."email", 
                            'phone', "t15"."phone", 'disabled', 
                            "t15"."disabled", 'role', "t15"."role", 
                            'companyId', "t15"."companyId", 
                            'permissionGroupId', "t15"."permissionGroupId", 
                            'vehicleTypes', "t15"."vehicleTypes", 
                            'createdAt', "t15"."createdAt", 
                            'updatedAt', "t15"."updatedAt", 
                            'team', "t15"."team", 'lastUnassignedTripId', 
                            "t15"."lastUnassignedTripId", 'metadata', 
                            "t15"."metadata"
                          ) AS "__prisma_data__" 
                        FROM 
                          (
                            SELECT 
                              "t14".* 
                            FROM 
                              "public"."User" AS "t14" 
                            WHERE 
                              "t11"."accountManagerId" = "t14"."id" 
                              /* root select */
                              ) AS "t15" 
                          /* inner select */
                          ) AS "t16" 
                      /* middle select */
                      ) AS "t17" 
                  /* outer select */
                  ) AS "Distributor_accountManager" ON true 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "Distributor_locations"."__prisma_data__" 
                    FROM 
                      "public"."_DistributorToLocation" AS "t18" 
                      LEFT JOIN LATERAL (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'id', "t20"."id", 'internalId', "t20"."internalId", 
                            'internalName', "t20"."internalName", 
                            'referenceId', "t20"."referenceId", 
                            'label', "t20"."label", 'description', 
                            "t20"."description", 'type', "t20"."type", 
                            'address', "t20"."address", 'district', 
                            "t20"."district", 'division', "t20"."division", 
                            'postCode', "t20"."postCode", 'country', 
                            "t20"."country", 'contactPerson', 
                            "t20"."contactPerson", 'phone', 
                            "t20"."phone", 'latitude', "t20"."latitude", 
                            'longitude', "t20"."longitude", 
                            'companyId', "t20"."companyId", 
                            'deletedAt', "t20"."deletedAt", 
                            'createdAt', "t20"."createdAt", 
                            'updatedAt', "t20"."updatedAt"
                          ) AS "__prisma_data__", 
                          "t20"."id" 
                        FROM 
                          (
                            SELECT 
                              "t19".* 
                            FROM 
                              "public"."Location" AS "t19" 
                            WHERE 
                              "t18"."B" = "t19"."id" 
                              /* root select */
                              ) AS "t20"
                      ) AS "Distributor_locations" ON true 
                    WHERE 
                      (
                        "t18"."A" = "t11"."id" 
                        AND "public"."Location"."type" = CAST(
                          $1 :: text AS "public"."LocationType"
                        )
                      )
                  ) AS "Distributor_locations_m2m_1"
              ) AS "Distributor_locations_m2m" ON true 
              /* inner select */
              ) AS "t12" 
          /* middle select */
          ) AS "t13" 
      /* outer select */
      ) AS "SalesOrder_distributor" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t25"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t24"."id", 'internalId', "t24"."internalId", 
                'internalName', "t24"."internalName", 
                'referenceId', "t24"."referenceId", 
                'label', "t24"."label", 'description', 
                "t24"."description", 'type', "t24"."type", 
                'address', "t24"."address", 'district', 
                "t24"."district", 'division', "t24"."division", 
                'postCode', "t24"."postCode", 'country', 
                "t24"."country", 'contactPerson', 
                "t24"."contactPerson", 'phone', 
                "t24"."phone", 'latitude', "t24"."latitude", 
                'longitude', "t24"."longitude", 
                'companyId', "t24"."companyId", 
                'deletedAt', "t24"."deletedAt", 
                'createdAt', "t24"."createdAt", 
                'updatedAt', "t24"."updatedAt"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t23".* 
                FROM 
                  "public"."Location" AS "t23" 
                WHERE 
                  "t1"."locationId" = "t23"."id" 
                  /* root select */
                  ) AS "t24" 
              /* inner select */
              ) AS "t25" 
          /* middle select */
          ) AS "t26" 
      /* outer select */
      ) AS "SalesOrder_location" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t29"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t28"."id", 'internalId', "t28"."internalId", 
                'internalName', "t28"."internalName", 
                'referenceId', "t28"."referenceId", 
                'label', "t28"."label", 'description', 
                "t28"."description", 'type', "t28"."type", 
                'address', "t28"."address", 'district', 
                "t28"."district", 'division', "t28"."division", 
                'postCode', "t28"."postCode", 'country', 
                "t28"."country", 'contactPerson', 
                "t28"."contactPerson", 'phone', 
                "t28"."phone", 'latitude', "t28"."latitude", 
                'longitude', "t28"."longitude", 
                'companyId', "t28"."companyId", 
                'deletedAt', "t28"."deletedAt", 
                'createdAt', "t28"."createdAt", 
                'updatedAt', "t28"."updatedAt"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t27".* 
                FROM 
                  "public"."Location" AS "t27" 
                WHERE 
                  "t1"."pickUpLocationId" = "t27"."id" 
                  /* root select */
                  ) AS "t28" 
              /* inner select */
              ) AS "t29" 
          /* middle select */
          ) AS "t30" 
      /* outer select */
      ) AS "SalesOrder_pickUpLocation" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t33"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t32"."id", 'authorId', "t32"."authorId", 
                'payerId', "t32"."payerId", 'payerResource', 
                "t32"."payerResource", 'payeeId', 
                "t32"."payeeId", 'payeeResource', 
                "t32"."payeeResource", 'paymentOption', 
                "t32"."paymentOption", 'paymentStatus', 
                "t32"."paymentStatus", 'type', "t32"."type", 
                'additionalNotes', "t32"."additionalNotes", 
                'amount', "t32"."amount", 'salesOrderId', 
                "t32"."salesOrderId", 'purchaseOrderId', 
                "t32"."purchaseOrderId", 'createdAt', 
                "t32"."createdAt", 'updatedAt', 
                "t32"."updatedAt"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t31".* 
                FROM 
                  "public"."Transaction" AS "t31" 
                WHERE 
                  "t1"."id" = "t31"."salesOrderId" 
                  /* root select */
                  ) AS "t32" 
              /* inner select */
              ) AS "t33" 
          /* middle select */
          ) AS "t34" 
      /* outer select */
      ) AS "SalesOrder_transactions" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t37"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t36"."id", 'productId', "t36"."productId", 
                'salesOrderId', "t36"."salesOrderId", 
                'packageQuantity', "t36"."packageQuantity", 
                'packageId', "t36"."packageId", 
                'quantity', "t36"."quantity", 'quantityUnit', 
                "t36"."quantityUnit", 'totalWeight', 
                "t36"."totalWeight", 'totalWeightUnit', 
                "t36"."totalWeightUnit", 'totalVolume', 
                "t36"."totalVolume", 'totalVolumeUnit', 
                "t36"."totalVolumeUnit", 'discount', 
                "t36"."discount", 'discountAmount', 
                "t36"."discountAmount", 'price', 
                "t36"."price", 'buyingPrice', "t36"."buyingPrice", 
                'productUnit', "t36"."productUnit", 
                'deliveredQuantity', "t36"."deliveredQuantity", 
                'deliveredPackageQuantity', "t36"."deliveredPackageQuantity", 
                'flaggedQuantity', "t36"."flaggedQuantity", 
                'createdAt', "t36"."createdAt", 
                'updatedAt', "t36"."updatedAt", 
                'inventoryItemId', "t36"."inventoryItemId", 
                'inventoryBatchItemId', "t36"."inventoryBatchItemId", 
                'approvedQuantity', "t36"."approvedQuantity", 
                'approvedPackageQuantity', "t36"."approvedPackageQuantity", 
                'isUpsell', "t36"."isUpsell", 'productId', 
                "t36"."productId", 'product', "SalesOrderItem_product"."__prisma_data__", 
                'salesOrderItemSpecifications', 
                "SalesOrderItem_salesOrderItemSpecifications"."__prisma_data__", 
                'packageId', "t36"."packageId", 
                'packaging', "SalesOrderItem_packaging"."__prisma_data__", 
                'inventoryBatchItemId', "t36"."inventoryBatchItemId", 
                'inventoryBatchItem', "SalesOrderItem_inventoryBatchItem"."__prisma_data__"
              ) AS "__prisma_data__", 
              "t36"."productId", 
              "t36"."id", 
              "t36"."packageId", 
              "t36"."inventoryBatchItemId" 
            FROM 
              (
                SELECT 
                  "t35".* 
                FROM 
                  "public"."SalesOrderItem" AS "t35" 
                WHERE 
                  "t1"."id" = "t35"."salesOrderId" 
                  /* root select */
                  ) AS "t36" 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "t41"."__prisma_data__" 
                    FROM 
                      (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'id', "t40"."id", 'summary', "t40"."summary", 
                            'name', "t40"."name", 'companyId', 
                            "t40"."companyId", 'imageUrls', 
                            "t40"."imageUrls", 'price', "t40"."price", 
                            'salePrice', "t40"."salePrice", 
                            'resellPrice', "t40"."resellPrice", 
                            'purchasePrice', "t40"."purchasePrice", 
                            'retailPrice', "t40"."retailPrice", 
                            'distributorPrice', "t40"."distributorPrice", 
                            'dealerPrice', "t40"."dealerPrice", 
                            'traderPrice', "t40"."traderPrice", 
                            'microEntrepreneurPrice', "t40"."microEntrepreneurPrice", 
                            'corporatePrice', "t40"."corporatePrice", 
                            'eCommerceCustomerPrice', "t40"."eCommerceCustomerPrice", 
                            'currency', "t40"."currency", 'sku', 
                            "t40"."sku", 'barcode', "t40"."barcode", 
                            'position', "t40"."position", 'shelfLife', 
                            "t40"."shelfLife", 'category', "t40"."category", 
                            'subCategory1', "t40"."subCategory1", 
                            'subCategory2', "t40"."subCategory2", 
                            'subCategory3', "t40"."subCategory3", 
                            'subCategory4', "t40"."subCategory4", 
                            'subCategory5', "t40"."subCategory5", 
                            'parentProductId', "t40"."parentProductId", 
                            'internalId', "t40"."internalId", 
                            'industry', "t40"."industry", 'deleted', 
                            "t40"."deleted", 'createdAt', "t40"."createdAt", 
                            'updatedAt', "t40"."updatedAt", 
                            'metadata', "t40"."metadata", 'type', 
                            "t40"."type", 'integrationId', "t40"."integrationId", 
                            'productSpecifications', "Product_productSpecifications"."__prisma_data__", 
                            'inventoryItems', "Product_inventoryItems"."__prisma_data__"
                          ) AS "__prisma_data__", 
                          "t40"."id" 
                        FROM 
                          (
                            SELECT 
                              "t39".* 
                            FROM 
                              "public"."Product" AS "t39" 
                            WHERE 
                              "t36"."productId" = "t39"."id" 
                              /* root select */
                              ) AS "t40" 
                          LEFT JOIN LATERAL (
                            SELECT 
                              COALESCE(
                                JSON_AGG("__prisma_data__"), 
                                '[]'
                              ) AS "__prisma_data__" 
                            FROM 
                              (
                                SELECT 
                                  "t45"."__prisma_data__" 
                                FROM 
                                  (
                                    SELECT 
                                      JSON_BUILD_OBJECT(
                                        'productId', "t44"."productId", 'specificationCompanyId', 
                                        "t44"."specificationCompanyId", 
                                        'specificationKey', "t44"."specificationKey", 
                                        'value', "t44"."value", 'unit', "t44"."unit", 
                                        'specificationCompanyId', "t44"."specificationCompanyId", 
                                        'specificationKey', "t44"."specificationKey", 
                                        'specification', "ProductSpecification_specification"."__prisma_data__"
                                      ) AS "__prisma_data__", 
                                      "t44"."specificationCompanyId", 
                                      "t44"."specificationKey" 
                                    FROM 
                                      (
                                        SELECT 
                                          "t43".* 
                                        FROM 
                                          "public"."ProductSpecification" AS "t43" 
                                        WHERE 
                                          "t40"."id" = "t43"."productId" 
                                          /* root select */
                                          ) AS "t44" 
                                      LEFT JOIN LATERAL (
                                        SELECT 
                                          COALESCE(
                                            JSON_AGG("__prisma_data__"), 
                                            '[]'
                                          ) AS "__prisma_data__" 
                                        FROM 
                                          (
                                            SELECT 
                                              "t49"."__prisma_data__" 
                                            FROM 
                                              (
                                                SELECT 
                                                  JSON_BUILD_OBJECT(
                                                    'label', "t48"."label", 'type', "t48"."type"
                                                  ) AS "__prisma_data__" 
                                                FROM 
                                                  (
                                                    SELECT 
                                                      "t47".* 
                                                    FROM 
                                                      "public"."Specification" AS "t47" 
                                                    WHERE 
                                                      (
                                                        "t44"."specificationCompanyId" = "t47"."companyId" 
                                                        AND "t44"."specificationKey" = "t47"."key"
                                                      ) 
                                                      /* root select */
                                                      ) AS "t48" 
                                                  /* inner select */
                                                  ) AS "t49" 
                                              /* middle select */
                                              ) AS "t50" 
                                          /* outer select */
                                          ) AS "ProductSpecification_specification" ON true 
                                      /* inner select */
                                      ) AS "t45" 
                                  /* middle select */
                                  ) AS "t46" 
                              /* outer select */
                              ) AS "Product_productSpecifications" ON true 
                          LEFT JOIN LATERAL (
                            SELECT 
                              COALESCE(
                                JSON_AGG("__prisma_data__"), 
                                '[]'
                              ) AS "__prisma_data__" 
                            FROM 
                              (
                                SELECT 
                                  "t53"."__prisma_data__" 
                                FROM 
                                  (
                                    SELECT 
                                      JSON_BUILD_OBJECT(
                                        'id', "t52"."id", 'productId', "t52"."productId", 
                                        'quantity', "t52"."quantity", 'wastageQuantity', 
                                        "t52"."wastageQuantity", 'expiredQuantity', 
                                        "t52"."expiredQuantity", 'locationId', 
                                        "t52"."locationId", 'companyId', 
                                        "t52"."companyId", 'batchNumber', 
                                        "t52"."batchNumber", 'createdAt', 
                                        "t52"."createdAt", 'updatedAt', 
                                        "t52"."updatedAt"
                                      ) AS "__prisma_data__", 
                                      "t52"."quantity" 
                                    FROM 
                                      (
                                        SELECT 
                                          "t51".* 
                                        FROM 
                                          "public"."InventoryItem" AS "t51" 
                                        WHERE 
                                          "t40"."id" = "t51"."productId" 
                                          /* root select */
                                          ) AS "t52" 
                                      /* inner select */
                                      ) AS "t53" 
                                WHERE 
                                  "t53"."quantity" > $2 
                                  /* middle select */
                                  ) AS "t54" 
                              /* outer select */
                              ) AS "Product_inventoryItems" ON true 
                          /* inner select */
                          ) AS "t41" 
                      /* middle select */
                      ) AS "t42" 
                  /* outer select */
                  ) AS "SalesOrderItem_product" ON true 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "t57"."__prisma_data__" 
                    FROM 
                      (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'salesOrderItemId', "t56"."salesOrderItemId", 
                            'specificationCompanyId', "t56"."specificationCompanyId", 
                            'specificationKey', "t56"."specificationKey", 
                            'value', "t56"."value", 'unit', "t56"."unit", 
                            'specificationCompanyId', "t56"."specificationCompanyId", 
                            'specificationKey', "t56"."specificationKey", 
                            'specification', "SalesOrderItemSpecification_specification"."__prisma_data__"
                          ) AS "__prisma_data__", 
                          "t56"."specificationCompanyId", 
                          "t56"."specificationKey" 
                        FROM 
                          (
                            SELECT 
                              "t55".* 
                            FROM 
                              "public"."SalesOrderItemSpecification" AS "t55" 
                            WHERE 
                              "t36"."id" = "t55"."salesOrderItemId" 
                              /* root select */
                              ) AS "t56" 
                          LEFT JOIN LATERAL (
                            SELECT 
                              COALESCE(
                                JSON_AGG("__prisma_data__"), 
                                '[]'
                              ) AS "__prisma_data__" 
                            FROM 
                              (
                                SELECT 
                                  "t61"."__prisma_data__" 
                                FROM 
                                  (
                                    SELECT 
                                      JSON_BUILD_OBJECT(
                                        'label', "t60"."label", 'type', "t60"."type"
                                      ) AS "__prisma_data__" 
                                    FROM 
                                      (
                                        SELECT 
                                          "t59".* 
                                        FROM 
                                          "public"."Specification" AS "t59" 
                                        WHERE 
                                          (
                                            "t56"."specificationCompanyId" = "t59"."companyId" 
                                            AND "t56"."specificationKey" = "t59"."key"
                                          ) 
                                          /* root select */
                                          ) AS "t60" 
                                      /* inner select */
                                      ) AS "t61" 
                                  /* middle select */
                                  ) AS "t62" 
                              /* outer select */
                              ) AS "SalesOrderItemSpecification_specification" ON true 
                          /* inner select */
                          ) AS "t57" 
                      /* middle select */
                      ) AS "t58" 
                  /* outer select */
                  ) AS "SalesOrderItem_salesOrderItemSpecifications" ON true 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "t65"."__prisma_data__" 
                    FROM 
                      (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'id', "t64"."id", 'name', "t64"."name", 
                            'productId', "t64"."productId", 
                            'type', "t64"."type", 'width', "t64"."width", 
                            'widthUnit', "t64"."widthUnit", 
                            'height', "t64"."height", 'heightUnit', 
                            "t64"."heightUnit", 'length', "t64"."length", 
                            'lengthUnit', "t64"."lengthUnit", 
                            'volume', "t64"."volume", 'volumeUnit', 
                            "t64"."volumeUnit", 'size', "t64"."size", 
                            'sizeUnit', "t64"."sizeUnit", 'createdAt', 
                            "t64"."createdAt", 'updatedAt', 
                            "t64"."updatedAt"
                          ) AS "__prisma_data__" 
                        FROM 
                          (
                            SELECT 
                              "t63".* 
                            FROM 
                              "public"."Package" AS "t63" 
                            WHERE 
                              "t36"."packageId" = "t63"."id" 
                              /* root select */
                              ) AS "t64" 
                          /* inner select */
                          ) AS "t65" 
                      /* middle select */
                      ) AS "t66" 
                  /* outer select */
                  ) AS "SalesOrderItem_packaging" ON true 
              LEFT JOIN LATERAL (
                SELECT 
                  COALESCE(
                    JSON_AGG("__prisma_data__"), 
                    '[]'
                  ) AS "__prisma_data__" 
                FROM 
                  (
                    SELECT 
                      "t69"."__prisma_data__" 
                    FROM 
                      (
                        SELECT 
                          JSON_BUILD_OBJECT(
                            'id', "t68"."id", 'inventoryItemId', 
                            "t68"."inventoryItemId", 'packageId', 
                            "t68"."packageId", 'productId', 
                            "t68"."productId", 'locationId', 
                            "t68"."locationId", 'companyId', 
                            "t68"."companyId", 'quantity', "t68"."quantity", 
                            'wastageQuantity', "t68"."wastageQuantity", 
                            'expiredQuantity', "t68"."expiredQuantity", 
                            'manufactureDate', "t68"."manufactureDate", 
                            'expiryDate', "t68"."expiryDate", 
                            'batchNumber', "t68"."batchNumber", 
                            'createdAt', "t68"."createdAt", 
                            'updatedAt', "t68"."updatedAt"
                          ) AS "__prisma_data__" 
                        FROM 
                          (
                            SELECT 
                              "t67".* 
                            FROM 
                              "public"."InventoryBatchItem" AS "t67" 
                            WHERE 
                              "t36"."inventoryBatchItemId" = "t67"."id" 
                              /* root select */
                              ) AS "t68" 
                          /* inner select */
                          ) AS "t69" 
                      /* middle select */
                      ) AS "t70" 
                  /* outer select */
                  ) AS "SalesOrderItem_inventoryBatchItem" ON true 
              /* inner select */
              ) AS "t37" 
          /* middle select */
          ) AS "t38" 
      /* outer select */
      ) AS "SalesOrder_salesOrderItems" ON true 
  LEFT JOIN LATERAL (
    SELECT 
      COALESCE(
        JSON_AGG("__prisma_data__"), 
        '[]'
      ) AS "__prisma_data__" 
    FROM 
      (
        SELECT 
          "t73"."__prisma_data__" 
        FROM 
          (
            SELECT 
              JSON_BUILD_OBJECT(
                'id', "t72"."id", 'name', "t72"."name", 
                'type', "t72"."type", 'partnerId', 
                "t72"."partnerId", 'disabled', "t72"."disabled"
              ) AS "__prisma_data__" 
            FROM 
              (
                SELECT 
                  "t71".* 
                FROM 
                  "public"."DeliveryPartner" AS "t71" 
                WHERE 
                  "t1"."preferredDeliveryPartner" = "t71"."id" 
                  /* root select */
                  ) AS "t72" 
              /* inner select */
              ) AS "t73" 
          /* middle select */
          ) AS "t74" 
      /* outer select */
      ) AS "SalesOrder_deliveryPartner" ON true 
WHERE 
  (
    "t1"."id" IN (
      $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, 
      $13, $14, $15, $16, $17, $18, $19, $20, 
      $21, $22, $23, $24, $25, $26, $27, $28, 
      $29, $30, $31, $32, $33, $34, $35
    ) 
    AND "t1"."companyId" = $36
  )

From the Logger in GCP I see this log from Postgres before the error is thrown:

db=postgres,user=postgres ERROR:  missing FROM-clause entry for table "Location" at character 6743

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v18.7.0

Prisma Version

prisma                  : 5.7.0
@prisma/client          : 5.7.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v18.7.0
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash    : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio                  : 0.495.0
Preview Features        : fullTextSearch, postgresqlExtensions, relationJoins

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions