mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #44232 from khasinski/update-docs-for-counter-cache-caveats
Add note in guide for a counter cache caveat [ci skip]
This commit is contained in:
commit
2189d97a2a
1 changed files with 9 additions and 1 deletions
|
@ -1108,7 +1108,15 @@ end
|
|||
NOTE: You only need to specify the `:counter_cache` option on the `belongs_to`
|
||||
side of the association.
|
||||
|
||||
Counter cache columns are added to the containing model's list of read-only attributes through `attr_readonly`.
|
||||
Counter cache columns are added to the owner model's list of read-only
|
||||
attributes through `attr_readonly`.
|
||||
|
||||
If for some reason you change the value of an owner model's primary key, and do
|
||||
not also update the foreign keys of the counted models, then the counter cache
|
||||
may have stale data. In other words, any orphaned models will still count
|
||||
towards the counter. To fix a stale counter cache, use [`reset_counters`][].
|
||||
|
||||
[`reset_counters`]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html#method-i-reset_counters
|
||||
|
||||
##### `:dependent`
|
||||
|
||||
|
|
Loading…
Reference in a new issue