My suggestion would be just to create a table payment, with a boolean column is_cash. It will have a field order_id, so it's a many-to-one relationship with the orders table. With this approach, you can also accommodate partial cash-partial card payment, by inserting 2 payment records but with different values for is_cash column. If payment details of cash and cashless are different, you can either have a separate table payment_details or just have a json column to store the details there.
Mar 28, 2020
4
Level 1
Multiple Polymorphic Relations in same Model
Hello All,
Continuing with my Ecommerce site where users can order food online, I'm stuck at another stage. Below are the tables in my app:
// users TABLE [Registered user of my site]
id, name and other fields
// guests TABLE [Guest user of my site]
id, name and other fields
Here, I have a Polymorphic Many to Many Relation between User <=> Order <=> Guest set in order table as:
// orders TABLE
id
orderable_id // Id of user who has placed the order
orderable_type // Type of a user - Guest or Registered
cart_amount
payment_mode // Currently it is set as enum('cash', 'cashless')
payment_status // Set as enum('pending', 'received', 'refund', 'refunded')
and other fields
Now going further in my development, I need to create 2 more tables to store payment details as:
- cash Table [Storing details of payment made in CASH]
- cashless Table [Storing details of payment made via CASHLESS methods]
I dont know whether i should create a relation between these 2 tables and the orders table? I believe i had to and that should be a POLYMORPHIC MANY TO MANY relation; but I dont know how to achieve that 'coz i'm already having a polymorphic relation in orders table [between users and guests].
Can anyone guide me in this?
Thanks in advance.
Much Regards Javed
Level 2
Please or to participate in this conversation.