我正在使用 postgres 9.6.1、Rails 4.2.0 和以下迁移:
class CreateStageBatches < ActiveRecord::Migration
def change
create_table :stage_batches do |t|
t.text :item_ids, array: true, default: []
end
end
end
如何创建整数数组?我试过:
[9] pry(main)> StageBatch.new item_ids: [1,2,3]
=> #<StageBatch id: nil, item_ids: ["1", "2", "3"]>
但它们是字符串。
查看 postgres docs看起来这是可能的,但我不确定我的迁移或实例化的语法是什么。
最佳答案
试试这个
t.integer 'item_ids', array: true
关于ruby-on-rails - 在 Postgres 中使用整数数组初始化模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42049802/