0

This is my data:

{   "bookingFee": "0",
    "inventoryId": "2001600236110005688",
    "inventoryItems": [{
        "operatorServiceCharge": "0.00",
        "passenger": {
            "age": "26",
            "gender": "MALE",
            "title": "Mr"
        },
        "seatName": "5",
        "serviceTax": "19.00"
    },
    {
        "operatorServiceCharge": "0.00",
        "passenger": {
            "age": "26",
            "gender": "MALE",
            "title": "Mr"
        },
        "seatName": "5",
        "serviceTax": "19.00"
    }],
    "status": "BOOKED",
    "tin": "123",
}

As you see , "inventoryItems" can be just single object sometimes and some times multiple arrays like above ! Can it be saved in mysql column like "inventoryItems" or i need to create a new joint table to add these ? And each "inventoryItems" items has passenger with various data also - how to handle that ?

Kindly suggest ? which is best practice ?

Shadow
  • 33,525
  • 10
  • 51
  • 64
samanthas
  • 79
  • 1
  • 7
  • to keep project extensible and do it with "best" practices you should create separate table for inventoryItems, and for Passenger as well. – Robert Nov 15 '20 at 16:56
  • You should make a seperate table. But if you would like to work this way you should take a look at NoSQL solutions like mongodb or firestore. – C.Schubert Nov 15 '20 at 16:57
  • Have been more than half through the project, cant change over to NoSQL now ! But, will try to make a separate table for each @C.Schubert – samanthas Nov 15 '20 at 17:05
  • 1
    Pls read about database normalisation, that's the best practice! – Shadow Nov 15 '20 at 17:13
  • if you are not going to change the data within the array too much and if there is no relation between this data to other data it is not bad at all – noshad b.e Nov 15 '20 at 17:17
  • Not bad at all for ? @noshadb.e – samanthas Nov 16 '20 at 03:11
  • @samanthas yes but consider the IF s that i wrote because in the end this is your code and you are the one that are going to work and create it and if you are good with arrays rather than sql queries then do it no one can judge you – noshad b.e Nov 16 '20 at 06:40

0 Answers0