Class: RuboCop::Cop::Obsession::Rails::MigrationBelongsTo
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::Rails::MigrationBelongsTo
- Defined in:
- lib/rubocop/cop/obsession/rails/migration_belongs_to.rb
Overview
This cop checks for migrations that use ‘references` instead of `belongs_to`.
Instead of adding ‘references` in migrations, use the `belongs_to` alias. It reads nicer and is more similar to the `belongs_to` declarations that you find in model code.
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/obsession/rails/migration_belongs_to.rb', line 33 def on_send(node) if add_reference?(node) add_offense(node, message: 'Use add_belongs_to instead of add_reference') elsif table_reference?(node) add_offense(node, message: 'Use t.belongs_to instead of t.references') end end |