method
readonly?
v1.1.6 -
Show latest stable
-
1 note -
Class: ActiveRecord::Base
- 1.0.0 (0)
- 1.1.6 (35)
- 1.2.6 (0)
- 2.0.3 (4)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-1)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
readonly?()
public
Records loaded through joins with piggy-back attributes will be marked as read only as they cannot be saved and return true to this query.
Register or
log in
to add new notes.
autonomous -
October 2, 2009
2 thanks
Making ActiveRecord models readonly
To force an ActiveRecord model to be read only you can do something along these lines:
class DelicateInfo < ActiveRecord::Base def readonly? true end end
When you try to save the model it will raise an ActiveRecord::ReadOnlyRecord exception:
info = DelicateInfo.first info.save # => ActiveRecord::ReadOnlyRecord
Note, however, that destroy and delete will still work on the model unless you intercept those calls