Rails custom foreign_key name on both table Rails custom foreign_key name on both table ruby-on-rails ruby-on-rails

Rails custom foreign_key name on both table


I bet this would work:

class User < ActiveRecord::Base  has_one :club, :foreign_key => :player_id, :primary_key => :uidendclass Club < ActiveRecord::Base  belongs_to :user, :foreign_key => :player_id, :primary_key => :uidend


Can Clubs have many Users and Users belong to many Clubs? If so, you may want to look at the http://guides.rubyonrails.org/association_basics.html page for the has_and_belongs_to_many relationship association method. If you use this association method, you will need to create a separate migration table to relate the user_id with the club_id.