ActiveRecord
foreign Key RB-LI1105Aside from being unnecessary, setting the foreign key prevents the inverse association from being inferred automatically, which can lead to unnecessary queries.
class Post
has_many :comments, foreign_key: 'post_id'
end
class Comment
belongs_to :post, foreign_key: 'post_id'
end
class Post
has_many :comments
end
class Comment
belongs_to :author, foreign_key: 'user_id'
end