logo
  • 教程列表
  • SO官方文檔
  • 多用途 ActiveRecord 列
    • 儲存物件
    • 如何
  1. StackOverflow 文件
  2. Ruby on Rails 教程
  3. 多用途 ActiveRecord 列
  4. 如何

如何

Created: November-22, 2018

在你的遷移中

class Users < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      ...
      t.text :preference
      t.text :tag
      ...
      t.timestamps
    end
  end
end

在你的模型中

class User < ActiveRecord::Base
    serialize :preferences, Hash  
    serialize :tags, Array
end
  • 儲存物件

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明