ActiveRecord 隐藏数据库中的字段

这是我在 StackOverflow 上的回答 https://stackoverflow.com/a/68485464/882410https://stackoverflow.com/a/68485464/882410
ActiveRecord::Migration.new.create_table :my_pages do |t|
  t.string :title
  t.string :body
  t.string :search_tsv
end

class MyPage < ActiveRecord::Base
  self.ignored_columns = %w[search_tsv]
end

MyPage.new

# => #<MyPage:0x00007fa4693b8278 id: nil, title: nil, body: nil>

class MyPage2 < ActiveRecord::Base
  self.table_name = 'my_pages'
  self.ignored_columns = %w[body search_tsv]
end

MyPage2.new

# => #<MyPage2:0x00007fa46845f808 id: nil, title: nil>
2021-10-20
0