Closed pirj closed 2 years ago
According to https://api.rubyonrails.org/v6.1/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_reference, foreign_key defaults to false.
foreign_key
false
When dependent: on belongs_to is not properly set, it may leave orphaned records behind on association deletion.
dependent:
belongs_to
It also prevents from early detection of code responsible for referral integrity violations.
After looking more closely, this boils down to providing an example to https://github.com/rubocop/rails-style-guide#foreign-key-constraints section.
According to https://api.rubyonrails.org/v6.1/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_reference,
foreign_key
defaults tofalse
.When
dependent:
onbelongs_to
is not properly set, it may leave orphaned records behind on association deletion.It also prevents from early detection of code responsible for referral integrity violations.