我有以下模型(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 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
如果它更容易,我可以删除它,但我对所有旧表执行此操作,因为我只是从中读取。
我确信这可以通过分配外键来完成,但我不确定关联这些的正确方法?
如果我缺少任何东西,请告诉我。