Skip to content

Commit f0d5006

Browse files
fsatelerpirj
authored andcommitted
Prefer appending to setting ignored_columns
Setting may overwrite previous assignments and that is almost always a mistake. See also rubocop/rubocop-rails#514
1 parent 73b9c68 commit f0d5006

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,21 @@ class Transaction < ApplicationRecord
404404
end
405405
----
406406

407+
=== Always append to `ignored_columns` [[append-ignored-columns]]
408+
409+
Avoid setting `ignored_columns`. It may overwrite previous assignments and that is almost always a mistake. Prefer appending to the list instead.
410+
411+
[source,ruby]
412+
----
413+
class Transaction < ActiveRecord::Base
414+
# bad - it may overwrite previous assignments
415+
self.ignored_columns = %i[legacy]
416+
# good - the value is appended to the list
417+
self.ignored_columns += %i[legacy]
418+
...
419+
end
420+
----
421+
407422
=== Enums [[enums]]
408423

409424
Prefer using the hash syntax for `enum`. Array makes the database values implicit

0 commit comments

Comments
 (0)