2

I'm using postgres 9.6.1, Rails 4.2.0, and the following migration:

class CreateStageBatches < ActiveRecord::Migration
  def change
    create_table :stage_batches do |t|
      t.text :item_ids, array: true, default: []
    end
  end
end

How do I create an array of integers? I've tried:

[9] pry(main)> StageBatch.new item_ids: [1,2,3]
=> #<StageBatch id: nil, item_ids: ["1", "2", "3"]>

But they are strings.

Looking at the postgres docs it looks like this is possible but I'm not sure what the syntax is for my migration or instantiation.

1 Answer 1

2

try this

 t.integer 'item_ids', array: true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.