Skip to content

Files

Latest commit

 

History

History
34 lines (24 loc) · 872 Bytes

Rails-HasManyOrHasOneDependent.md

File metadata and controls

34 lines (24 loc) · 872 Bytes

Pattern: Missing :dependent option for has_many/has_one

Issue: -

Description

This rule looks for has_many or has_one associations that don't specify a :dependent option.

Examples

# bad
class User < ActiveRecord::Base
  has_many :comments
  has_one :avatar
end

# good
class User < ActiveRecord::Base
  has_many :comments, dependent: :restrict_with_exception
  has_one :avatar, dependent: :destroy
end

Default configuration

Attribute Value
Include app/models/**/*.rb

Further Reading