Skip to content

Commit 533eacf

Browse files
authored
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 8d88cb6 commit 533eacf

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
@@ -408,6 +408,21 @@ class Transaction < ActiveRecord::Base
408408
end
409409
----
410410

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

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

0 commit comments

Comments
 (0)