I'm re-doing an app and migrating data from an old app. The some of the models names will be the same, though not all of them.
I'm writing a rake task to connect to the old database, read the records, do some stuff and write the result into a new database. Because some of the table names are the same the model names will be the same, so I want to name space my models like so
module OldData
class Account <ActiveRecord::Base
has_many :subcriptions
establish_connection $olddb
end
class Subscription <ActiveRecord::Base
belongs_to :account
establish_connection $olddb
end
end
where $olddb is a hash required to connect to the old database
I can open account records and read them ok, but the Account model doesn't have a subscriptions association. The latest Rails documentation suggest that this should work. but it doesn't.
Any advice?
maybe you should try to set class name explicitly
has_many :subcriptions, class_name: 'OldData::Subscription'
and
belongs_to :account, class_name: 'OldData::Account'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With