0

This im hoping is a simple one. but i have a table that is called product. One column is called Parts. Basically i need to store multiple arrays in there, with each array holding a reference to a part ID and the quantity required. I dont really know the best way to set it up. There could be up to about 25 parts for one product yet another have 3.

Any advice would be a great help!

Cheers Tom

2
  • 1
    Why don't you want to setup a link table, product_part? Commented Apr 3, 2013 at 18:46
  • 2
    Don't do it. Set it up relational. Commented Apr 3, 2013 at 18:47

1 Answer 1

3

It seems best to setup a Many-to-Many relationship with another table and link to that. If you insist on storing the array as a string - use JSON, you can always encode your array(s) to JSON and store it as such, then when you pull it out, you merely decode from JSON back to array.

Sign up to request clarification or add additional context in comments.

2 Comments

how will i store the foreign id and quantity together? as one product may have a different quantity requirement of a part to another product so i cant set quantity in the foreign table
In a cross reference table, just keep |product_id|part_id|quantity| The link I provided demonstrates this with the bill_product table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.