Ruby on rails Rails:属于特定列

Ruby on rails Rails:属于特定列,ruby-on-rails,ruby,orm,model,relation,Ruby On Rails,Ruby,Orm,Model,Relation,我有以下型号: 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 class用户“短键” 结束 类用户

我有以下型号:

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
class用户

在这种情况下,如何添加“属于”:远程餐厅?

使用自定义外键和主键添加“属于”

class User < ActiveRecord::Base
    belongs_to :remote_restaurant, :foreign_key => "INFO_SHORT_RD", :primary_key=>"shortRD"
end
class用户“信息短键”;:主键=>“短键”
结束
类用户
你能试试
属于:远程餐厅,外键:'shortRD'
?我现在无法测试它,也记不清确切的语法。那个INFO\u SHORT\u RD常量是怎么回事?
class User < ActiveRecord::Base
  belongs_to :restaurant, class_name: 'RemoteRestaurant', foreign_key: :shortRD, primary_key: :INFO_SHORT_KEY
end