James Q Quick
06/17/2022, 7:11 PMInvoice
has many LineItems
. My db model is setup where the LineItem
has a reference as invoiceId
to the primary key of the corresponding invoice. I'm wondering how can query and create invoices that includes that line items themselves? The only thing I found in the docs is to include the foreign key relationship which I already have setup. So, I know I can query an invoice from a line item, but how do I query line items from an invoice?Needle
06/17/2022, 7:11 PMgaryaustin
06/17/2022, 8:02 PM.from('messages')
.select('*, test!inner(*)')
.eq('test.message_id',7)
Where 7 is the message id and test is a table with an fk to messages table.
It returns: imageJames Q Quick
06/19/2022, 8:12 PMtest!inner(*)
saying to grab all items and call them an array called test
then the selector is in the eq
line specifying which items we want to get it?garyaustin
06/19/2022, 8:14 PMgaryaustin
06/19/2022, 8:16 PMJames Q Quick
06/19/2022, 8:25 PMeq
works specifically with a dynamic parameter. Like if I'm querying for an array of Invoices and their associated LineItems? I tried doing .eq(`LineItem.invoiceId`, `Invoice.id`);
but I'm getting a new error invalid input syntax for type bigint: "Invoice.id"'
garyaustin
06/19/2022, 8:26 PMJames Q Quick
06/19/2022, 8:27 PMgaryaustin
06/19/2022, 8:27 PMgaryaustin
06/19/2022, 8:28 PMJames Q Quick
06/19/2022, 8:30 PMgaryaustin
06/19/2022, 8:31 PMJames Q Quick
06/19/2022, 8:31 PMconst { data: loadedInvoices, error: invoicesError } = await supabase
.from('Invoice')
.select(
`
id, status, subject, dueDate, issueDate,
discount, notes, amount,
client:clientId (id, name, email, address, city, state, zip, phone),
user:userId (id, name, email, address, city, state, zip, phone),
LineItem!inner(*)
`
).eq(`LineItem.invoiceId`, 51);
garyaustin
06/19/2022, 8:32 PMJames Q Quick
06/19/2022, 8:32 PMgaryaustin
06/19/2022, 8:34 PMJames Q Quick
06/19/2022, 8:34 PMgaryaustin
06/19/2022, 8:36 PMgaryaustin
06/19/2022, 8:39 PMJames Q Quick
06/19/2022, 8:39 PMconst { data: loadedInvoices, error: invoicesError } = await supabase
.from('Invoice')
.select(
`
id, status, subject, dueDate, issueDate,
discount, notes, amount,
client:clientId (id, name, email, address, city, state, zip, phone),
user:userId (id, name, email, address, city, state, zip, phone),
LineItem: lineItems
`
);
garyaustin
06/19/2022, 8:39 PMJames Q Quick
06/19/2022, 8:40 PMJames Q Quick
06/19/2022, 8:40 PMgaryaustin
06/19/2022, 8:41 PMJames Q Quick
06/19/2022, 8:42 PMgaryaustin
06/19/2022, 8:42 PMJames Q Quick
06/19/2022, 8:43 PMJames Q Quick
06/19/2022, 8:44 PMLineItem!inner(*): lineItems
garyaustin
06/19/2022, 8:44 PMJames Q Quick
06/19/2022, 8:44 PMLineItem
instead of lineItems
James Q Quick
06/19/2022, 8:55 PM