I have a model distributed into many databases. Here is an example:
class Timetablerange < ActiveRecord::Base
self.table_name = "TimetableRange"
def self.integration(integration)
self.establish_connection(integration.to_sym)
return self
end
end
So when I want to fetch an instance from one database:
Timetablerange.integration(:integration_id).find(1)
I need to get the database_name from an instance without using:
Timetable.connection.current_database
Since it can be different if I use this:
instance_a = Timetablerange.integration(:integration_1).find(1)
instance_b = Timetablerange.integration(:integration_2).find(1)
At this time Timetable.connection.current_database = :integration_2 but instance_a was loaded from :integration_1.
I've tried to use:
instance_a.connection_handler.connection_pools
And it lists all the connections. But how can I now witch database was instance_a loaded from?
Thanks so much for the help!