Skip to content

What is the foreign key relationships in database to connect sales_order with each sale_order_Item?

Foreach customer, I need to retrieve every order.
Foreach order, I need to retrieve each product item.

The tables are sales_order and sale_order_Item, but I don’t see a connection. How are these mapped to each other?

In a nutshell, I am trying to create an array of every invoice with its related data.

invoices = [
"Name" => "John Doe",
"Items Invoiced" => [
                     "Product" => 'Maple Wood Table',
                     "Price" => 999.99,
                     "QTY" => 1
                     "Row Total" => 1074.33
                     ],
"Billing Address => [...],
"Account Information" => [...]
],
invoices = [
"Name" => "Jane Doe",
"Items Invoiced" => [
                     "Product" => 'Red Oak Table',
                     "Price" => 1299.99,
                     "QTY" => 1
                     "Row Total" => 1434.25
                     ],
"Billing Address => [...],
"Account Information" => [...]
],

//And so on for every invoice in the database