2017-02-05 43 views
2
整數數組

我使用的Postgres 9.6.1,Rails的4.2.0和以下遷移:初始化模型與Postgres的

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它看起來像這是可能的,但我不知道我的遷移或實例的語法是什麼。

回答

2

試試這個

t.integer 'item_ids', array: true