Skip to content

Commit

Permalink
Merge pull request #45654 from shouichi/improve-readonly-doc
Browse files Browse the repository at this point in the history
Improve ActiveRecord::QueryMethods.readonly doc [skip ci]
  • Loading branch information
p8 committed Oct 8, 2022
2 parents d399609 + cdbbb96 commit 3258979
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -1074,12 +1074,18 @@ def none! # :nodoc:
where!("1=0").extending!(NullRelation)
end

# Sets readonly attributes for the returned relation. If value is
# true (default), attempting to update a record will result in an error.
# Mark a relation as readonly. Attempting to update a record will result in
# an error.
#
# users = User.readonly
# users.first.save
# => ActiveRecord::ReadOnlyRecord: User is marked as readonly
#
# To make a readonly relation writable, pass +false+.
#
# users.readonly(false)
# users.first.save
# => true
def readonly(value = true)
spawn.readonly!(value)
end
Expand Down

0 comments on commit 3258979

Please sign in to comment.