Hi, so I have an object that has a bunch of normal...
# server
Hi, so I have an object that has a bunch of normal fields, and then it has an array field with enums in it. I have the object stored in the table with an integer ID, but I'm not quite sure how to store the array, I assume I need another table, but I'm not sure how to link it all together. Also, I need to make sure the order of the array is retained inside the table. Any and all help would be greatly appreciated!
Assuming you're using a relational db, there are generally two options for storing the model - • serialize the array of enums and store it as a string as one column in the table. Generally, acceptable if a small number of enum values will be stored. You'll have to remember to update the string values with a db migration if you ever change the enum. Otherwise, you can implement versioning to handle serialization changes • store the mapping of enum values to the parent object in a separate table. Use an ID column that will act as a foreign key to enforce the parent-child relationship. How you read the two tables back into a single kotlin object depends on what framework you use for your ORM/DSL. It's easy to do in all of them though
Alright, thank you!
Additionally eg Postgres has an array datatype that can be used for this. https://www.postgresql.org/docs/current/arrays.html