【发布时间】:2012-09-17 20:39:53
【问题描述】:
我有以下模型(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
如果它更容易,我可以删除它,但我对所有旧表执行此操作,因为我只是从中读取。
我确定这可以通过分配外键来完成,但我不确定关联这些的正确方法?
如果我遗漏了什么,请告诉我。
【问题讨论】:
标签: ruby-on-rails foreign-keys associations primary-key