-1

I have the following model:

class User < ActiveRecord::Base

  #method that I want to delete and replace with belongs_to
  def restaurant
      RemoteRestaurant.find_by_shortRD(self.INFO_SHORT_RD)
  end
end

How can I add a belongs_to :remote_restaurant in this case?

2 Answers2

0

Add belongs_to with your custom foreign_key and primary_key

class User < ActiveRecord::Base
    belongs_to :remote_restaurant, :foreign_key => "INFO_SHORT_RD", :primary_key=>"shortRD"
end
Siva
  • 7,780
  • 6
  • 47
  • 54
0
class User < ActiveRecord::Base
  belongs_to :restaurant, class_name: 'RemoteRestaurant', foreign_key: :shortRD, primary_key: :INFO_SHORT_KEY
end
BroiSatse
  • 44,031
  • 8
  • 61
  • 86