[CC''ing rails list, in case anyone else is interested]
Jacob Robbins wrote:> hey steve,
> I have the exact same problem using multiple db''s and webrick as
the one you posted to the ruby list. Can''t find any responses to your
email in the archives for that list, did you ever resolve it or just do
something else?
I''m not sure if it just magically went away (that''s happened
to me with
several problems), or if it was because I changed my approach.
> The docs say that ActiveRecord::Base keeps a hash of connections per
model, but i only see one connection when i call ActiveRecord::Base.connection,
so i don''t know where this hash is visible.
It''s a bit more obvious if you look at the source to
establish_connection [0].
Essentially, it just means you can call it to override the DB connection
only for a given model (and inherited models).
However, I''ve taken a bit of a departure from the standard Productized
app.
In addition to having per-site databases, I also wanted a single shared DB for
all of my rails apps. In here I stuff all my user, password, and access
tables (so me and other users don''t need separate accounts for
different
sites), as well as various domain tables.
I had originally tried the multiple DB trick, but abandoned it as it
didn''t
allow for eager loading of associations, and I got sick of seeing all those
"SELECT * FROM users WHERE id = 1". I don''t know if those
would get cached in
production or not, but I didn''t want to mess with it.
Since I can assume I''ll keep my global DB on the same server instance
as the
site DBs, I wound up just using a single connection (for the site DB), and
then overriding the table names to include the DB name ("rails"),
e.g.:
class User < ActiveRecord::Base
set_table_name "rails.users"
has_and_belongs_to_many :roles, :join_table =>
"rails.roles_users"
...
There''s also probably a DRYer way of doing this (suggestions welcome!),
and it
may very well be MySQL-specific. but it works for me (YMMV).
[0] http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000738
=============================================================================Steve
Sloan Hacker / Drummer / Super Genius
------------------------------------------------------------------------------
These opinions expressed above are mine, not those of my employer.
Their opinion is that I should be working right now.
==============================================================================