我想以这种格式在rails中保存PostgreSQL中的一组结构:
INSERT, UPDATE, DELETE
然而,当我保存它们时,我得到了字符串格式的数组,而这不是我想要的:
[#<struct User name=“Jack”, occupation=[“student”, "waiter"]>,
#<struct User name=“Jason”, occupation=[“teacher”]>,
#<struct User name=“Jeric”, occupation=[“athlete”, "trainer"]>,
#<struct User name=“Jeffrey”, occupation=[“scientist”]>]
在我的迁移文件中,我已经这样做了:
["#<struct User name=“Jack”, occupation=[“student”, "waiter"]>”,
"#<struct User name=“Jason”, occupation=[“teacher”]>”,
"#<struct User name=“Jeric”, occupation=[“athlete”, "trainer"]>”,
"#<struct User name=“Jeffrey”, occupation=[“scientist”]>”]
当我将class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :name, null: false
t.string :occupation, array: true, default: []
t.timestamps
end
end
end
更改为t.string
时,数据库迁移无效。
我想知道我应该在模式中为职业列提供什么类型的类型,以及如何编写迁移文件?