You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with Drizzle ORM and trying to fetch invoices along with related contacts and transactions. The transactions table has a referenceId column that can reference multiple tables (invoices, credits, etc.), and I use a type column to distinguish between these relationships. Here's the code I'm using:
const getInvoices = async (): Promise<Invoice[]> => {
return db.query.invoices.findMany({
orderBy: [desc(invoices.invoiceNumber)],
columns: {
contactId: false, // Exclude contactId from the invoice fields
},
with: {
contact: {
columns: {
id: true,
name: true,
},
},
transactions: {
where: and(
eq(transactions.referenceId, invoices.id), // Match transactions to invoices
eq(transactions.type, 'invoice') // Filter by transaction type
),
},
},
});
};
However, I'm running into the following error: There is not enough information to infer relation "invoices.transactions".
Schema Overview
Here are the relevant parts of my schema: invoicesTable
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working with Drizzle ORM and trying to fetch invoices along with related contacts and transactions. The
transactions
table has areferenceId
column that can reference multiple tables (invoices
,credits
, etc.), and I use a type column to distinguish between these relationships. Here's the code I'm using:However, I'm running into the following error:
There is not enough information to infer relation "invoices.transactions".
Schema Overview
Here are the relevant parts of my schema:
invoices
Tabletransactions
TableBeta Was this translation helpful? Give feedback.
All reactions