0

I am designing a database with stores, product, product_categories, product_options and of course I want to implement the ordering system.

To explain further:

  • A store has some products
  • A product can have some categories (e.g if we are talking about food then those categories would be: size, toppings, ingredients)
  • A product category will contain the category's options( e.g if we talking about a product with category size then the options would be: small, medium, large)

Database EER diagram enter image description here

The question is how to implement the order table. For example lets say we have the following order:

{
  "product": {
    "id":1,
    "categories":{
      "category1": {
        "id":1,
        "name":"size",
        "options":{
          "option1":{
            "id":3,
            "name":"large",
            "price":"5.4"
          }
        }
      },
      "category2": {
        "id":1,
        "name":"ingredients",
        "options":{
          "option1":{
            "id":2,
            "name":"onions",
            "price":"0.8"
          },
          "option2":{
            "id":3,
            "name":"tomato",
            "price":"0.5"
          }
        }
      }
    }
  }
}

Best solution so far using mysql, is to create the corresponding order_product, order_product_categories, order_product_options and the main orders table in order to keep up with the the volume of information that an order contains.

Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
marioskamperis
  • 135
  • 1
  • 10
  • Surely an order will be two tables, order and order_product. The product table will contain product_id, product_category_id and product_options_id and the quantity of this particular item they've ordered. So it contains JUST the id's of the particular option they've bought. – Nigel Ren May 27 '17 at 18:59
  • Yes of course but imagine having an order_product table with 5 different categories under that product then the order_product_options would have at least 5 distinct rows regarding each category and so many rows as to include every single option under each category. In my eyes it does not seem so efficient. – marioskamperis May 27 '17 at 19:23
  • No - you just have an order_line table (not order_product as I said before), this JUST has the ids from the product_* tables, these would just be a foreign key to the product_* tables and not copying the tables. – Nigel Ren May 27 '17 at 20:33
  • Maybe i do not understand what you are saying. How would you insert an order for a: Product_id: 1 , Product_name:Pizza Product_category_id:1 , Product_category_name: Size Product_category_id:2 , Product_category_name: Ingredients Product_option_id:1, Product_category_id:1 , product_option_name: large Product_option_id:2, Product_category_id:2 , product_option_name: onion Product_option_id:3, Product_category_id:2 , product_option_name: bacon (I am so sorry for the reading difficulty) – marioskamperis May 27 '17 at 20:50
  • So how do you work the price out? If (for example) one category gives you the size and another set of categories give you the ingredients, surely the amount of ingredients are related to the size - which also affects the price. – Nigel Ren May 28 '17 at 05:56
  • What do "most efficient" and "better" mean? What is "in my opinion seems" summarizing? Please give *some* design for orders. Please do not use comments to clarifiy, instead edit your question. PS There's no normalization here. – philipxy May 28 '17 at 09:19
  • @philipxy I have given a Json representation of an order maybe that will help clarify my question. PS I had the belief that be breaking product to the corresponding product_options and product_categories I was using 1NF and 2NF normalization. – marioskamperis May 28 '17 at 13:14
  • That is helpful. But what DDL do you propose? Please also act on the rest of my last comment. PS Normalization is used to mean a lot of things, but it really only means modifying relational designs to have no relation-valued attributes or to components in higher normal forms. It is ubiquitously (erroneously) *used* to mean moving from an non-relational design to a relational one, or from a relational design with (vaguely-, inadequately- & nonsensibly- defined) ["non-atomic"](https://stackoverflow.com/a/24038895/3404097) types to one without. (2NF & up use FDs. Where are yours?) – philipxy May 29 '17 at 02:06
  • What do you mean by DDL? Give me an example. – marioskamperis May 31 '17 at 08:40

0 Answers0