Как представить запрос SQL с несколькими JOIN в Prisma?

Имеется такой запрос:
SELECT
	bp.id AS bp_id,
	streams.id AS stream_id
FROM business_profiles AS bp
INNER JOIN accounts AS acc on acc.business_profile_id = bp.id
INNER JOIN streams ON streams.stream_owner_id = acc.id
WHERE streams.id in (?);


Пытаюсь представить его в Prisma ORM, но что-то не очень получается (впервые работаю с ним). Помогите советом.

укороченный вариант schema.prisma
model Account {
  id                  BigInt    @id @default(autoincrement())
  business_profile    BusinessProfile @relation(fields: [business_profile_id], references: [id])
  business_profile_id BigInt
  ...
  streams             Stream[]
}

model Stream {
  id                BigInt   @id @default(autoincrement())
  stream_owner_id   BigInt
  account           Account @relation(fields: [stream_owner_id], references: [id])
  ...
}

model BusinessProfile {
  id          BigInt   @id @default(autoincrement())
  ...
  accounts    Account[]
}

Мои попытки
const bpIDs = await this.client.businessProfile.findMany({
			include: {
				accounts: {
					include: {
						streams: true,
					},
				},
			},
			where: {
				accounts: {
					
				},
			},
			// select: {
			// 	accounts: {
			// 		select: {
			// 			streams: {
			// 				where: {
			// 					id: {
			// 						in: streamIDs,
			// 					},
			// 				},
			// 			},
			// 		},
			// 	},
			// },
		});
		console.log(bpIDs);
  • Вопрос задан
  • 107 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы