Ruby

Ruby

Made by DeepSource

Incorrect Order of ActiveRecord Callbacks RB-LI1103

Anti-pattern
Major
Autofix

ActiveRecord callbacks, such as before_save, after_save, etc., are methods that are executed at specific points in the lifecycle of a model. However, in this case, the callbacks are not being executed in the correct order, leading to unexpected behavior.

Bad practice

class Person < ApplicationRecord
  after_commit :after_commit_callback
  before_validation :before_validation_callback
end

Recommended

class Person < ApplicationRecord
  before_validation :before_validation_callback
  after_commit :after_commit_callback
end

References

  1. Active Record Callbacks