ActiveRecord
foreign Key RB-LI1105foreign_key
is redundant.15 belongs_to :client,
16 class_name: "Eve::Character",
17 primary_key: "character_id",
18 foreign_key: "client_id",19 optional: true
20end
Aside 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