你好我是rails的新手我正在尝试应用连接。我有两个表零售商和请求。在这两个表中我都有一个列共同的'retailer_Code'。所以我想获取列数据匹配的位置。
@retailers=Request.joins("LEFT OUTER JOIN retailers on requests.retailer_code = retailers.retailer_code ").select(:status,:created_at,:shop_name,:request_type)
这是我的查询并在@retailers
class Request < ActiveRecord::Base
has_many :retailers
end
class Retailers < ActiveRecord::Base
belongs_to :request
end
答案 0 :(得分:-1)
通过关联,可以明确提及外键。在你的情况下,它是:foreign_key =&gt; &#34; retailer_Code&#34;
class Request < ActiveRecord::Base
has_many :retailers, :foreign_key => "retailer_Code"
end
class Retailers < ActiveRecord::Base
belongs_to :request, :foreign_key => "retailer_Code"
end