Skip to content

Files

Latest commit

 

History

History
33 lines (23 loc) · 616 Bytes

Rails-RedundantForeignKey.md

File metadata and controls

33 lines (23 loc) · 616 Bytes

Pattern: Redundant :foreign_key option

Issue: -

Description

Checks for associations where the :foreign_key option is redundant.

Examples

# bad
class Post
  has_many :comments, foreign_key: 'post_id'
end

class Comment
  belongs_to :post, foreign_key: 'post_id'
end

# good
class Post
  has_many :comments
end

class Comment
  belongs_to :author, foreign_key: 'user_id'
end

Further Reading