What is the best way to make my table column read only? disable the setter method? The column is set by postgres trigger, so I don't want to set it in the application level
让我的表列只读的最好方法是什么?禁用setter方法?列是由postgres触发器设置的,所以我不想在应用程序级别设置它
1 个解决方案
#1
4
It seems like you look for ActiveRecord::Base attr_readonly
:
看起来你在寻找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"
#1
4
It seems like you look for ActiveRecord::Base attr_readonly
:
看起来你在寻找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"