There is a purchase_orders
table, which holds purchase orders.
There is another table emp_payouts
table, which holds payment to be paid to an employee and their details.
There is a payment_transactions
table which holds payment transactions made to someone from the app, only outgoing payments.
Each entity (purchase order, employee payouts etc) can have multiple payment transactions.
How can I store transactions for both entities in that table?
I have two solutions in my mind but still I am in doubt.
Having
purchase_order_id
andemp_payout_id
inpayment_transactions
table.In this case, one of the column will always hold null values
payment_transactions -------------------------- id | purchase_order_id | emp_payout_id | amount
Having pivot tables for both entities:
purchase_order_transactions
andemp_payout_transactions
In this case, entities purchase orders and employee payouts are being associated with multiple transactions which is fine, but the same thing is also true for payment transactions. While, a payment transaction should only be related to one purchase order or employee payouts.
purchase_order_transactions -------------------------- id | purchase_order_id | payment_transaction_id emp_payout_transactions -------------------------- id | emp_payout_id | payment_transaction_id