If you are on PostgreSQL, you may try different solutions, such as:
- Array column type
create_table :table_name do |t|
...
t.string 'array_column_name', array: true
...
end
add_index :table_name, :array_column_name, using: 'gin'
# Usage
YourModel.create(array_column_name: ["value1", "value2"])
- Or you can try to store your data as JSON
create_table :table_name do |t|
t.json 'json_column_name'
end
# Usage
YoutModel.create(json_column_name: { key1: "val1", key2: ["val21", "val22"]})
and parse your json more flexible, to array and other structures.
More information you can see at official Rails documentation
hstoreforpostgreswhich stores hashes