How to store a list in a db column

后端 未结 6 848
悲哀的现实
悲哀的现实 2020-11-30 19:25

I would like to store an object FOO in a database. Lets say FOO contains three integers and a list of \"Fruits\".

The list can have any len

6条回答
  •  天涯浪人
    2020-11-30 19:59

    Some databases allow multiple values to be stored in a single column of a single row, but it is generally more convenient to use a separate table.

    Create a table with two columns, one that contains pointers to the primary key of the objects table, and one that contains pointers to the primary key of the fruit table. Then, if an object has three fruit, there are three rows in the object_fruit table that all all point to the same object, but to three different fruit.

提交回复
热议问题