Multiple database problem in rails 1.1?


#1

Hi …

We are constructing at rails GUI using two differant databases, and this
seems to work out nicely using a “establish_connection” per model, where
each model enherit directly from ActiveRecord::Base.

But ! I like to use a model where we can inherit from one parent class
that handles the connection exactly as descripted in this document :

http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/Connections.rdoc

The only problem is that my database (postgres) seems to be asked to
find this parent class, but this should not have happend !

My Models looks like this :

– app/models/safe_record.rb

class SafeRecord < ActiveRecord::Base
establish_connection “safe_#{RAILS_ENV}”
end

– app/models/event.rb

class Event < SafeRecord
end

– Taken from script/console when doing a “e = Event.new”

ActiveRecord::StatementInvalid: PGError: ERROR: relation “safe_record”
does not exist

Why are rails looking for “safe_record” ?

/BL


#2

Bo Lorentsen wrote:

– app/models/safe_record.rb

class SafeRecord < ActiveRecord::Base
establish_connection “safe_#{RAILS_ENV}”
end

– app/models/event.rb

class Event < SafeRecord
end
The answer to this is to add the following to the SafeRecord class :

self.abstract_class = true

Amazing :slight_smile:

This works from 1.14.0 of ActiveRecord …

/BL