gpt4 book ai didi

ruby-on-rails - 在 Postgres 中使用整数数组初始化模型

转载 作者:数据小太阳 更新时间:2023-10-29 08:58:42 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com