I have the following models (venmas is a legacy database so I can’t change it):
models/venmas.rb
class Venmas < ActiveRecord::Base
establish_connection "turnkey"
end
models/yard.rb
class Yard < ActiveRecord::Base
end
I want to be able to do:
Yard.first.venmas.first # to get the first record of venmas for that yard
Here is what Yard looks like:
#<Yard id: 1, name: "nyssa", created_at: "2012-08-07 16:58:02", updated_at: "2012-08-07 16:58:02">
and Venmas:
#<Venmas VENDOR_NUMBER: " ", ... , yard: "nyssa"> # there are a lot of columns in this one and they aren't important.
One other monkey wrench I have this in inflections.rb:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'venmas', 'venmas'
end
I can remove this if it makes it easier, but I do this with all the legacy tables because I just read from them.
I am sure this can be done by assigning the foreign_key, but I am not really sure the right way to associate these?
Please let me know if there is anything that I am missing.
Figured it out
Still open to better solutions…