Since you're trying to establish a has_many
belongs_to
relationship, simply define the primary key on the has_many
model, then direct the belongs_to
model to utilize that primary key as its foreign key:
# app/models/billing_plan.rb
class BillingPlan < ActiveRecord::Base
self.table_name = "billing_plans" # Seems unnecessary, as the table name by default is `billing_plans`
has_many :accounts, primary_key: 'name'
end
# app/models/account.rb
class Account < ActiveRecord::Base # Remember to subclass `ActiveRecord::Base`
has_many :contacts
belongs_to :user, primary_key: :email, foreign_key: :billing_email_address
has_one :billing_plan, foreign_key: 'name'
end