Skip to content

Commit f735328

Browse files
authored
Merge pull request rails#51248 from Earlopain/ar-guides-links
Add mention that methods can also skip callbacks to the AR Validations Guide [ci-skip]
2 parents 08b49f1 + d3f16a7 commit f735328

File tree

2 files changed

+93
-45
lines changed

2 files changed

+93
-45
lines changed

guides/source/active_record_callbacks.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,45 @@ Skipping Callbacks
310310

311311
Just as with validations, it is also possible to skip callbacks by using the following methods:
312312

313-
* `decrement!`
314-
* `decrement_counter`
315-
* `delete`
316-
* `delete_all`
317-
* `delete_by`
318-
* `increment!`
319-
* `increment_counter`
320-
* `insert`
321-
* `insert!`
322-
* `insert_all`
323-
* `insert_all!`
324-
* `touch_all`
325-
* `update_column`
326-
* `update_columns`
327-
* `update_all`
328-
* `update_counters`
329-
* `upsert`
330-
* `upsert_all`
331-
332-
These methods should be used with caution, however, because important business rules and application logic may be kept in callbacks. Bypassing them without understanding the potential implications may lead to invalid data.
313+
* [`decrement!`][]
314+
* [`decrement_counter`][]
315+
* [`delete`][]
316+
* [`delete_all`][]
317+
* [`delete_by`][]
318+
* [`increment!`][]
319+
* [`increment_counter`][]
320+
* [`insert`][]
321+
* [`insert!`][]
322+
* [`insert_all`][]
323+
* [`insert_all!`][]
324+
* [`touch_all`][]
325+
* [`update_column`][]
326+
* [`update_columns`][]
327+
* [`update_all`][]
328+
* [`update_counters`][]
329+
* [`upsert`][]
330+
* [`upsert_all`][]
331+
332+
These methods should be used with caution, however, because important business rules and application logic may be kept in callbacks. Bypassing them without understanding the potential implications may lead to invalid data. Refer to the method documentation to learn more.
333+
334+
[`decrement!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-decrement-21
335+
[`decrement_counter`]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html#method-i-decrement_counter
336+
[`delete`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-delete
337+
[`delete_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all
338+
[`delete_by`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_by
339+
[`increment!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-increment-21
340+
[`increment_counter`]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html#method-i-increment_counter
341+
[`insert`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert
342+
[`insert!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert-21
343+
[`insert_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert_all
344+
[`insert_all!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert_all-21
345+
[`touch_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-touch_all
346+
[`update_column`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_column
347+
[`update_columns`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_columns
348+
[`update_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-update_all
349+
[`update_counters`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-update_counters
350+
[`upsert`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-upsert
351+
[`upsert_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-upsert_all
333352

334353
Halting Execution
335354
-----------------

guides/source/active_record_validations.md

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,46 +119,75 @@ careful.
119119
The following methods trigger validations, and will save the object to the
120120
database only if the object is valid:
121121

122-
* `create`
123-
* `create!`
124-
* `save`
125-
* `save!`
126-
* `update`
127-
* `update!`
122+
* [`create`][]
123+
* [`create!`][]
124+
* [`save`][]
125+
* [`save!`][]
126+
* [`update`][]
127+
* [`update!`][]
128128

129129
The bang versions (e.g. `save!`) raise an exception if the record is invalid.
130130
The non-bang versions don't: `save` and `update` return `false`, and
131131
`create` returns the object.
132132

133+
[`create`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-create
134+
[`create!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-create-21
135+
[`save`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save
136+
[`save!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21
137+
[`update`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update
138+
[`update!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update-21
139+
133140
### Skipping Validations
134141

135142
The following methods skip validations, and will save the object to the
136143
database regardless of its validity. They should be used with caution.
137-
138-
* `decrement!`
139-
* `decrement_counter`
140-
* `increment!`
141-
* `increment_counter`
142-
* `insert`
143-
* `insert!`
144-
* `insert_all`
145-
* `insert_all!`
146-
* `toggle!`
147-
* `touch`
148-
* `touch_all`
149-
* `update_all`
150-
* `update_attribute`
151-
* `update_column`
152-
* `update_columns`
153-
* `update_counters`
154-
* `upsert`
155-
* `upsert_all`
144+
Refer to the method documentation to learn more.
145+
146+
* [`decrement!`][]
147+
* [`decrement_counter`][]
148+
* [`increment!`][]
149+
* [`increment_counter`][]
150+
* [`insert`][]
151+
* [`insert!`][]
152+
* [`insert_all`][]
153+
* [`insert_all!`][]
154+
* [`toggle!`][]
155+
* [`touch`][]
156+
* [`touch_all`][]
157+
* [`update_all`][]
158+
* [`update_attribute`][]
159+
* [`update_attribute!`][]
160+
* [`update_column`][]
161+
* [`update_columns`][]
162+
* [`update_counters`][]
163+
* [`upsert`][]
164+
* [`upsert_all`][]
156165

157166
Note that `save` also has the ability to skip validations if passed `validate:
158167
false` as an argument. This technique should be used with caution.
159168

160169
* `save(validate: false)`
161170

171+
[`decrement!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-decrement-21
172+
[`decrement_counter`]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html#method-i-decrement_counter
173+
[`increment!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-increment-21
174+
[`increment_counter`]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html#method-i-increment_counter
175+
[`insert`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert
176+
[`insert!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert-21
177+
[`insert_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert_all
178+
[`insert_all!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-insert_all-21
179+
[`toggle!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-toggle-21
180+
[`touch`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch
181+
[`touch_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-touch_all
182+
[`update_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-update_all
183+
[`update_attribute`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_attribute
184+
[`update_attribute!`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_attribute-21
185+
[`update_column`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_column
186+
[`update_columns`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_columns
187+
[`update_counters`]: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-update_counters
188+
[`upsert`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-upsert
189+
[`upsert_all`]: https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-upsert_all
190+
162191
### `valid?` and `invalid?`
163192

164193
Before saving an Active Record object, Rails runs your validations.

0 commit comments

Comments
 (0)