3
什麼是使我的表列只讀的最佳方式是什麼?禁用setter方法?列是由Postgres設置觸發,所以我不想把它在應用層面Make Rails表列屬性只讀
什麼是使我的表列只讀的最佳方式是什麼?禁用setter方法?列是由Postgres設置觸發,所以我不想把它在應用層面Make Rails表列屬性只讀
好像你找的ActiveRecord :: Base的attr_readonly
:
class Foo < ActiveRecord::Base
attr_readonly :bar
end
foo = Foo.create(bar: "first_value")
foo.bar
=> "first_value"
foo.update(bar: "second_value") #column `bar` ignored in SQL query
foo.bar
=> "first_value"