Rails: Adding migration to add an array (default empty)

后端 未结 3 936
小蘑菇
小蘑菇 2020-12-24 12:14

I\'m trying to add a column called share to one of my resources. The idea is that users can upload documents and share them with other (specific) users, and the array contai

3条回答
  •  半阙折子戏
    2020-12-24 12:49

    if you want support all databases you must serialize the array in a String

    class Documents < ActiveRecord::Base
     serialize :share
    end
    
    class AddShareToDocuments < ActiveRecord::Migration
     def change
       add_column :documents, :share, :string, :default => []
     end 
    end
    

    In case of Postgresql and array datatype I found https://coderwall.com/p/sud9ja

提交回复
热议问题