> But, a user comes and creates an account and picks his/her favorite
> apples and saves that config.  On development you can use
> has_and_belongs_to_many for both the user and apples and it works
> great, all one database.
>
> But, on production I need to store:
> 1) The user account on the production_user db
> 2) the HABTM table on the user db because the read only databases are
> optimized for reads only and there are a lot of searches going on for
> apples apparently :)
>

Each model can use a different database connection. Assuming :readonly  
is a configuration defined in database.yml you can do

class Apple < ActiveRecord::Base
   establish_connection :readonly
end

to have it use that connection

> But, the apples themselves are on the read only database.  So if I say
> apples.users or users.apples i need to make connections to pull the
> interesting ides out of the corresponding tables, and make connections
> to the other databases in order to get my data.
>
> I could use a lot of
> apple.users_from_production if RAILS_ENV == 'production'
> apple.users unless  RAILS_ENV == 'production'
> all over the place, but that seems hokie.
>
> Anyone else had to do this and what was your solution?  Any help would
> be appreciated.  Another solution would be helpful too, but the
> database structure is pretty well set.  The readonly side needs to be
> very scalable and nodes need to be able to disappear and reappear
> based on load, hence haproxy so I can't 'just go to one db and use
> memcache everywhere'. :D
>
> Thanks.
> Erik
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to