@@ -162,49 +162,6 @@ Name | Default value | Configurable values
162
162
--- | --- | ---
163
163
Include | ` **/test/**/* ` | Array
164
164
165
- ## Rails/BelongsTo
166
-
167
- Enabled by default | Supports autocorrection
168
- --- | ---
169
- Enabled | Yes
170
-
171
- This cop looks for belongs_to associations where we control whether the
172
- association is required via the deprecated ` required ` option instead.
173
-
174
- Since Rails 5, belongs_to associations are required by default and this
175
- can be controlled through the use of ` optional: true ` .
176
-
177
- From the release notes:
178
-
179
- belongs_to will now trigger a validation error by default if the
180
- association is not present. You can turn this off on a
181
- per-association basis with optional: true. Also deprecate required
182
- option in favor of optional for belongs_to. (Pull Request)
183
-
184
- In the case that the developer is doing ` required: false ` , we
185
- definitely want to autocorrect to ` optional: true ` .
186
-
187
- However, without knowing whether they've set overriden the default
188
- value of ` config.active_record.belongs_to_required_by_default ` , we
189
- can't say whether it's safe to remove ` required: true ` or replace it
190
- with ` optional: false ` (or, similarly, remove a superfluous `optional:
191
- false` ). Therefore, in the cases we're using ` required: true`, we'll
192
- highlight that ` required ` is deprecated but otherwise do nothing.
193
-
194
- ### Examples
195
-
196
- ``` ruby
197
- # bad
198
- class Post < ApplicationRecord
199
- belongs_to :blog , required: false
200
- end
201
-
202
- # good
203
- class Post < ApplicationRecord
204
- belongs_to :blog , optional: true
205
- end
206
- ```
207
-
208
165
## Rails/Blank
209
166
210
167
Enabled by default | Supports autocorrection
0 commit comments