Set_table_name on the fly

Hi. I have a model that connects to a database, does something, connects
to a different database, does something, and so on.

The switching of the databases appears to work, as calling:

MyModel.connection.instance_eval { @config[:database] }

Yields the correct database.

After changing databases I also call:


However, upon issuing a query:


I receive an error similar to:

Unknown column ‘old_table_name.column’ in ‘where clause’…

Any ideas?

Any ideas?

Yeah. :slight_smile:

My initial post left out some important details. I wasn’t running:


I was running:


And that’s where Rails is falling back on the inflected/guessed table
name. I could probably change the has_many directive to be dynamic, but
I opted for something more like:

User.find(:all, :conditions => [ ‘associated_id => ?’, id ])

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs