Skip to content

Commit c47974a

Browse files
Improve allow_deprecated_singular_associations_name config doc [ci-skip]
Follow-up to rails#45344. This tweaks the description, fleshes out the code example, and fixes the default value listed for 7.1.
1 parent 9badb0f commit c47974a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

guides/source/configuring.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Below are the default values associated with each target version. In cases of co
6767
- [`config.action_controller.allow_deprecated_parameters_hash_equality`](#config-action-controller-allow-deprecated-parameters-hash-equality): `false`
6868
- [`config.log_file_size`](#config-log-file-size): `100.megabytes`
6969
- [`config.active_record.sqlite3_adapter_strict_strings_by_default`](#config-active-record-sqlite3-adapter-strict-strings-by-default): `false`
70-
- [`config.active_record.allow_deprecated_singular_associations_name`](#config-active-record-allow-deprecated-singular-associations-name): `true`
70+
- [`config.active_record.allow_deprecated_singular_associations_name`](#config-active-record-allow-deprecated-singular-associations-name): `false`
7171

7272

7373
#### Default Values for Target Version 7.0
@@ -1031,23 +1031,29 @@ should be large enough to accommodate both the foreground threads (.e.g web serv
10311031
10321032
#### `config.active_record.allow_deprecated_singular_associations_name`
10331033
1034-
This maintains the deprecated associations behavior where singular associations can be referred to in where clauses by their plural name. Enable this configuration option to opt into the new behavior.
1035-
1036-
before,
1034+
This enables deprecated behavior wherein singular associations can be referred to by their plural name in `where` clauses. Setting this to `false` is more performant.
10371035
10381036
```ruby
1039-
class Post
1040-
end
1041-
1042-
class Comment
1037+
class Comment < ActiveRecord::Base
10431038
belongs_to :post
10441039
end
10451040
1046-
post = Post.first
1047-
Comment.where(posts: post) # deprecated
1048-
Comment.where(post: post) # instead use the relation's name
1041+
Comment.where(post: post_id).count # => 5
1042+
1043+
# When `allow_deprecated_singular_associations_name` is true:
1044+
Comment.where(posts: post_id).count # => 5 (deprecation warning)
1045+
1046+
# When `allow_deprecated_singular_associations_name` is false:
1047+
Comment.where(posts: post_id).count # => error
10491048
```
10501049
1050+
The default value depends on the `config.load_defaults` target version:
1051+
1052+
| Starting with version | The default value is |
1053+
| --------------------- | -------------------- |
1054+
| (original) | `true` |
1055+
| 7.1 | `false` |
1056+
10511057
#### `ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans`
10521058
10531059
Controls whether the Active Record MySQL adapter will consider all `tinyint(1)` columns as booleans. Defaults to `true`.

0 commit comments

Comments
 (0)