Skip to content

Commit bad7ff1

Browse files
authored
Merge pull request rails#51450 from fatkodima/remove-stale-comment
Counter cache columns are not marked as readonly [skip ci]
2 parents 3461e00 + bb779f9 commit bad7ff1

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ def has_one(name, scope = nil, **options)
18161816
# named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging Comment class)
18171817
# is used on the associate class (such as a Post class) - that is the migration for
18181818
# <tt>#{table_name}_count</tt> is created on the associate class (such that <tt>Post.comments_count</tt> will
1819-
# return the count cached, see note below). You can also specify a custom counter
1819+
# return the count cached). You can also specify a custom counter
18201820
# cache column by providing a column name instead of a +true+/+false+ value to this
18211821
# option (e.g., <tt>counter_cache: :my_custom_counter</tt>.)
18221822
#
@@ -1829,12 +1829,10 @@ def has_one(name, scope = nil, **options)
18291829
# use <tt>counter_cache: { active: false }</tt>.
18301830
# If you also need to specify a custom column name, use <tt>counter_cache: { active: false, column: :my_custom_counter }</tt>.
18311831
#
1832-
# Note: Specifying a counter cache will add it to that model's list of readonly attributes
1833-
# using +attr_readonly+.
1834-
# [+:polymorphic+]
1835-
# Specify this association is a polymorphic association by passing +true+.
18361832
# Note: If you've enabled the counter cache, then you may want to add the counter cache attribute
18371833
# to the +attr_readonly+ list in the associated classes (e.g. <tt>class Post; attr_readonly :comments_count; end</tt>).
1834+
# [+:polymorphic+]
1835+
# Specify this association is a polymorphic association by passing +true+.
18381836
# Note: Since polymorphic associations rely on storing class names in the database, make sure to update the class names in the
18391837
# <tt>*_type</tt> polymorphic type column of the corresponding rows.
18401838
# [+:validate+]

guides/source/association_basics.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,6 @@ end
12271227
NOTE: You only need to specify the `:counter_cache` option on the `belongs_to`
12281228
side of the association.
12291229

1230-
Counter cache columns are added to the owner model's list of read-only
1231-
attributes through `attr_readonly`.
1232-
12331230
Starting to use counter caches on existing large tables can be troublesome, because the column
12341231
values must be backfilled separately of the column addition (to not lock the table for too long)
12351232
and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use

0 commit comments

Comments
 (0)