database design - MySQL table for saving a quantity to a 1:M relationship -


i have tables called invoice, item , invoice_item. invoice item tables has invoice_id , item_id columns store 1:m type relationship, invoice can have many items.

now want somehow store information item quantity. suitable create invoice_item_quantity table, store invoice_id, item_id , invoice_item_quantity values, respectively? or there more optimal solution?

i over-engineering this, adding item_quantity column invoice table won't work cause can have many different types of items, there no context there.

i need way store model this:

  • invoice
    • item 1 x 5
    • item 2 x 2
    • item 3 x 15

how can optimally store quantities in model above?

i may misunderstanding, sounds have many-to-many relationship between invoice , item tables, , using junction table support invoice_item table (this junction has one-to-many relationship both invoice , item).

if looking typical, normalized database design, storing quantity on invoice_item table good. idea make invoice id , item id compound primary key on junction table.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -