Counter cache columns are not marked as readonly [skip ci]

This commit is contained in:
fatkodima 2024-03-29 23:57:48 +02:00
parent 3461e0073f
commit bb779f929f
2 changed files with 3 additions and 8 deletions

View File

@ -1816,7 +1816,7 @@ module ActiveRecord
# named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging Comment class)
# is used on the associate class (such as a Post class) - that is the migration for
# <tt>#{table_name}_count</tt> is created on the associate class (such that <tt>Post.comments_count</tt> will
# return the count cached, see note below). You can also specify a custom counter
# return the count cached). You can also specify a custom counter
# cache column by providing a column name instead of a +true+/+false+ value to this
# option (e.g., <tt>counter_cache: :my_custom_counter</tt>.)
#
@ -1829,12 +1829,10 @@ module ActiveRecord
# use <tt>counter_cache: { active: false }</tt>.
# If you also need to specify a custom column name, use <tt>counter_cache: { active: false, column: :my_custom_counter }</tt>.
#
# Note: Specifying a counter cache will add it to that model's list of readonly attributes
# using +attr_readonly+.
# [+:polymorphic+]
# Specify this association is a polymorphic association by passing +true+.
# Note: If you've enabled the counter cache, then you may want to add the counter cache attribute
# to the +attr_readonly+ list in the associated classes (e.g. <tt>class Post; attr_readonly :comments_count; end</tt>).
# [+:polymorphic+]
# Specify this association is a polymorphic association by passing +true+.
# Note: Since polymorphic associations rely on storing class names in the database, make sure to update the class names in the
# <tt>*_type</tt> polymorphic type column of the corresponding rows.
# [+:validate+]

View File

@ -1227,9 +1227,6 @@ 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 owner model's list of read-only
attributes through `attr_readonly`.
Starting to use counter caches on existing large tables can be troublesome, because the column
values must be backfilled separately of the column addition (to not lock the table for too long)
and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use