Deeply nested "with" param in query is failing

I'm trying to query with deeply nested with param and getting weird error. Am I doing anything wrong or is this a bug? drizzle-orm: 0.31.2 Typescript code:
const quotation = await db.query.quotations.findFirst({
with: {
quotationLines: {
with: {
materialVariant: {
with: {
materialVariantsToSuppliers: {
with: {
supplier: true,
},
},
},
},
supplier: true,
},
orderBy: [asc(quotationItemLines.created_at), asc(quotationItemLines.id)],
},
quotationItems: {
with: {
billOfMaterials: true,
},
},
},
where: (table, { eq }) => eq(table.id, id),
})
const quotation = await db.query.quotations.findFirst({
with: {
quotationLines: {
with: {
materialVariant: {
with: {
materialVariantsToSuppliers: {
with: {
supplier: true,
},
},
},
},
supplier: true,
},
orderBy: [asc(quotationItemLines.created_at), asc(quotationItemLines.id)],
},
quotationItems: {
with: {
billOfMaterials: true,
},
},
},
where: (table, { eq }) => eq(table.id, id),
})
Error:
code: '42703',
detail: 'There is a column named "supplier_id" in table "quotations_quotationLines_materialVariant_materialVariantsToSup", but it cannot be referenced from this part of the query.',
hint: 'To reference that column, you must mark this subquery with LATERAL.',
code: '42703',
detail: 'There is a column named "supplier_id" in table "quotations_quotationLines_materialVariant_materialVariantsToSup", but it cannot be referenced from this part of the query.',
hint: 'To reference that column, you must mark this subquery with LATERAL.',
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server