Forum: Ruby on Rails Multiple database problem in rails 1.1 ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bo Lorentsen (Guest)
on 2006-05-04 16:34
(Received via mailing list)
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/Tec...

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
Bo Lorentsen (Guest)
on 2006-05-04 17:21
(Received via mailing list)
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 :-)

This works from 1.14.0 of ActiveRecord ...

/BL
This topic is locked and can not be replied to.