Skip to content

Commit 2d49c1c

Browse files
Merge pull request rails#45449 from jonathanhefner/allow_deprecated_singular_associations_name-config-guide
Improve `allow_deprecated_singular_associations_name` config doc [ci-skip]
2 parents 4a94f4a + c47974a commit 2d49c1c

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
@@ -1046,23 +1046,29 @@ should be large enough to accommodate both the foreground threads (.e.g web serv
10461046

10471047
#### `config.active_record.allow_deprecated_singular_associations_name`
10481048

1049-
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.
1050-
1051-
before,
1049+
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.
10521050

10531051
```ruby
1054-
class Post
1055-
end
1056-
1057-
class Comment
1052+
class Comment < ActiveRecord::Base
10581053
belongs_to :post
10591054
end
10601055
1061-
post = Post.first
1062-
Comment.where(posts: post) # deprecated
1063-
Comment.where(post: post) # instead use the relation's name
1056+
Comment.where(post: post_id).count # => 5
1057+
1058+
# When `allow_deprecated_singular_associations_name` is true:
1059+
Comment.where(posts: post_id).count # => 5 (deprecation warning)
1060+
1061+
# When `allow_deprecated_singular_associations_name` is false:
1062+
Comment.where(posts: post_id).count # => error
10641063
```
10651064

1065+
The default value depends on the `config.load_defaults` target version:
1066+
1067+
| Starting with version | The default value is |
1068+
| --------------------- | -------------------- |
1069+
| (original) | `true` |
1070+
| 7.1 | `false` |
1071+
10661072
#### `ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans`
10671073

10681074
Controls whether the Active Record MySQL adapter will consider all `tinyint(1)` columns as booleans. Defaults to `true`.

0 commit comments

Comments
 (0)