Re: Changing a model''s database connection

Frederick Cheung
Mon, 19 Jul 2010 18:32:33 -0000

On Jul 19, 6:08 pm, Michaël
<michael.b...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> Hi,
> I''ve tried the following, but it doesn''t seem to have any
effect:
>
>      def build_report:
>
>         Customer.establish_connection(
>             :adapter  => "mysql",
>             :host     => "hostname",
>             :username => "user",
>             :password => "password",
>             :database => "schema"
>         )
>
>         @customer = Customer.find(@criteria[:customer_id])
>
>         ..... <report logic here>
>
>      end
>
> Is it possible to achieve what I want to do this way, or do I need to
> look along other lines?
>

this would only affect queries done against the customers table.
queries to any other tables would still go to the ''normal''
database.
Is that what''s happening?

Fred
> Many thanks,
> Michaël