0
我有以下型号(venmas是旧的数据库,所以我不能改变它):活动记录外键关联轨
models/venmas.rb
class Venmas < ActiveRecord::Base
establish_connection "turnkey"
end
models/yard.rb
class Yard < ActiveRecord::Base
end
我希望能够做到:
Yard.first.venmas.first # to get the first record of venmas for that yard
这是院子里的样子:
#<Yard id: 1, name: "nyssa", created_at: "2012-08-07 16:58:02", updated_at: "2012-08-07 16:58:02">
和Venmas:
#<Venmas VENDOR_NUMBER: " ", ... , yard: "nyssa"> # there are a lot of columns in this one and they aren't important.
另外一个活动扳手我这是inflections.rb:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'venmas', 'venmas'
end
我可以删除这一点,如果它可以更容易,但我这样做的所有遗留表,因为我刚刚从他们读。
我相信这可以通过分配foreign_key来完成,但我不确定将这些关联的正确方法吗?
请让我知道是否有任何我缺少的东西。