I have database tables that look like this : Table 1 : transaction
id|buyer_id|transaction_date
----------------------------
1 | 1 |2020-01-01
2 | 4 |2020-03-04
3 | 6 |2020-11-12
----------------------------
Table 2 : transaction_detail
id|transaction_id|item_id|qty
--------------------------------
1| 1 | 1 | 3 |
2| 1 | 4 | 1 |
3| 1 | 6 | 2 |
--------------------------------
transaction_detai.transaction_id is a foreign key to transaction.id
How can I select data in transaction table but also get all the transaction_detail as a child ? If I use join, it will generate all data in one row. I need something just like this :
Array(
[0] => Master\Entities\Transaction Object
(
[id:protected] =>
[buyer_id:protected] =>
[transaction_date:protected] =>
[transaction_detail:protected]=>
Array(
[0] => Master\Entities\TransactionDetail Object
(
[id:protected] =>
[transaction_id:protected] =>
[item_id:protected] =>
[qty:protected] =>
)
)
)
)