0
我想通過使用活動記錄從表中刪除列。請找到以下代碼片段如何刪除活動記錄中的表列
require "active_record"
require 'sqlite3'
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'test_one')
class Account < ActiveRecord::Base
table_name = "AccountBean"
primary_key = "process_id"
remove_column "xxx" // I need this type of method to remove column "xxx" from accounts table
end
ActiveRecord中是否有任何滿足此要求的類方法?
是的,但使用的連接方法,即使我們知道我們在表代表類(帳戶)是有點奇怪 – pramod
@pramod - 方法'remove_column'只適用於遷移,因此你不能指望有一個很好的簡單的API來改變你的表結構從'行動iveRecord'模型:) – Magnuss