Merge pull request #52044 from p8/activerecord/tiny-description-fix

Improve documentation of RecordNotSaved and RecordNotDestroyed [ci-skip]
This commit is contained in:
Petrik de Heus 2024-06-08 10:17:34 +02:00 committed by GitHub
commit 8d416d09fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 8 deletions

View File

@ -130,9 +130,17 @@ module ActiveRecord
# Raised by {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!] and
# {ActiveRecord::Base.update_attribute!}[rdoc-ref:Persistence#update_attribute!]
# methods when a record is failed to validate or cannot be saved due to any of the
# methods when a record failed to validate or cannot be saved due to any of the
# <tt>before_*</tt> callbacks throwing +:abort+. See
# ActiveRecord::Callbacks for further details
# ActiveRecord::Callbacks for further details.
#
# class Product < ActiveRecord::Base
# before_save do
# throw :abort if price < 0
# end
# end
#
# Product.create! # => raises an ActiveRecord::RecordNotSaved
class RecordNotSaved < ActiveRecordError
attr_reader :record
@ -143,15 +151,17 @@ module ActiveRecord
end
# Raised by {ActiveRecord::Base#destroy!}[rdoc-ref:Persistence#destroy!]
# when a call to {#destroy}[rdoc-ref:Persistence#destroy]
# would return false.
# when a record cannot be destroyed due to any of the
# <tt>before_destroy</tt> callbacks throwing +:abort+. See
# ActiveRecord::Callbacks for further details.
#
# begin
# complex_operation_that_internally_calls_destroy!
# rescue ActiveRecord::RecordNotDestroyed => invalid
# puts invalid.record.errors
# class User < ActiveRecord::Base
# before_destroy do
# throw :abort if still_active?
# end
# end
#
# User.first.destroy! # => raises an ActiveRecord::RecordNotDestroyed
class RecordNotDestroyed < ActiveRecordError
attr_reader :record