Skip to content

Commit

Permalink
Prefer appending to setting ignored_columns
Browse files Browse the repository at this point in the history
Setting may overwrite previous assignments and that is almost always a mistake.

See also rubocop/rubocop-rails#514
  • Loading branch information
fsateler authored and pirj committed May 5, 2022
1 parent 73b9c68 commit 420937f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,22 @@ class Transaction < ApplicationRecord
end
----

=== Always append to `ignored_columns` [[append-ignored-columns]]

Avoid setting `ignored_columns`. It may overwrite previous assignments and that is almost always a mistake. Prefer appending to the list instead.

[source,ruby]
----
class Transaction < ApplicationRecord
# bad - it may overwrite previous assignments
self.ignored_columns = %i[legacy]
# good - the value is appended to the list
self.ignored_columns += %i[legacy]
...
end
----

=== Enums [[enums]]

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

0 comments on commit 420937f

Please sign in to comment.